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