From 3e2ffa545f5717c7b8dc76a5a68126fcd43b8891 Mon Sep 17 00:00:00 2001 From: miraclesu Date: Thu, 24 Mar 2016 20:03:45 +0800 Subject: [PATCH] orm: fix postgres returning id error --- orm/db_postgres.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/orm/db_postgres.go b/orm/db_postgres.go index 7dbef95a..be4cd0bc 100644 --- a/orm/db_postgres.go +++ b/orm/db_postgres.go @@ -123,14 +123,16 @@ func (d *dbBasePostgres) ReplaceMarks(query *string) { } // make returning sql support for postgresql. -func (d *dbBasePostgres) HasReturningID(mi *modelInfo, query *string) (has bool) { - if mi.fields.pk.auto { - if query != nil { - *query = fmt.Sprintf(`%s RETURNING "%s"`, *query, mi.fields.pk.column) - } - has = true +func (d *dbBasePostgres) HasReturningID(mi *modelInfo, query *string) bool { + fi := mi.fields.pk + if fi.fieldType&IsPositiveIntegerField == 0 && fi.fieldType&IsIntegerField == 0 { + return false } - return + + if query != nil { + *query = fmt.Sprintf(`%s RETURNING "%s"`, *query, fi.column) + } + return true } // show table sql for postgresql.