From aec6c895687be2691d5ccb842ebd3f0b12171cf2 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 5 Aug 2021 00:21:17 +0800 Subject: [PATCH] Fix postgres bug --- schemas/quote_test.go | 4 ++++ session_insert.go | 1 + 2 files changed, 5 insertions(+) diff --git a/schemas/quote_test.go b/schemas/quote_test.go index 8e351dc0..061a6ea2 100644 --- a/schemas/quote_test.go +++ b/schemas/quote_test.go @@ -176,6 +176,10 @@ func TestReplace(t *testing.T) { "UPDATE table SET `a` = ~ `a`, `b`='abc`'", "UPDATE table SET [a] = ~ [a], [b]='abc`'", }, + { + "INSERT INTO `insert_where` (`height`,`name`,`repo_id`,`width`,`index`) SELECT $1,$2,$3,$4,coalesce(MAX(`index`),0)+1 FROM `insert_where` WHERE (`repo_id`=$5)", + "INSERT INTO [insert_where] ([height],[name],[repo_id],[width],[index]) SELECT $1,$2,$3,$4,coalesce(MAX([index]),0)+1 FROM [insert_where] WHERE ([repo_id]=$5)", + }, } for _, kase := range kases { diff --git a/session_insert.go b/session_insert.go index 0a763524..990fdbff 100644 --- a/session_insert.go +++ b/session_insert.go @@ -283,6 +283,7 @@ func (session *Session) insertStruct(bean interface{}) (int64, error) { if err != nil { return 0, err } + sqlStr = session.engine.dialect.Quoter().Replace(sqlStr) handleAfterInsertProcessorFunc := func(bean interface{}) { if session.isAutoCommit {