From a13b7a6acbb32b80ceac63de1ae3576bbb0cdb45 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Wed, 10 Feb 2021 14:11:29 +0800 Subject: [PATCH] Fix OnConflict where order for postgres, close #4073 --- clause/on_conflict.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clause/on_conflict.go b/clause/on_conflict.go index 5ecd8e93..f0c3d7e7 100644 --- a/clause/on_conflict.go +++ b/clause/on_conflict.go @@ -26,12 +26,6 @@ func (onConflict OnConflict) Build(builder Builder) { builder.WriteString(`) `) } - if len(onConflict.Where.Exprs) > 0 { - builder.WriteString("WHERE ") - onConflict.Where.Build(builder) - builder.WriteByte(' ') - } - if onConflict.OnConstraint != "" { builder.WriteString("ON CONSTRAINT ") builder.WriteString(onConflict.OnConstraint) @@ -44,6 +38,12 @@ func (onConflict OnConflict) Build(builder Builder) { builder.WriteString("DO UPDATE SET ") onConflict.DoUpdates.Build(builder) } + + if len(onConflict.Where.Exprs) > 0 { + builder.WriteString("WHERE ") + onConflict.Where.Build(builder) + builder.WriteByte(' ') + } } // MergeClause merge onConflict clauses