From dd8bf88eb9abdac71a290222ee2f70cf293c662b Mon Sep 17 00:00:00 2001 From: Vitaliy Shein <40733789+VitalyShein@users.noreply.github.com> Date: Mon, 7 Jun 2021 05:39:00 +0300 Subject: [PATCH] add Target where clause for on conflict (#4442) Co-authored-by: Vitaliy Shein --- clause/on_conflict.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/clause/on_conflict.go b/clause/on_conflict.go index 127d9bc1..64ee7f53 100644 --- a/clause/on_conflict.go +++ b/clause/on_conflict.go @@ -3,6 +3,7 @@ package clause type OnConflict struct { Columns []Column Where Where + TargetWhere Where OnConstraint string DoNothing bool DoUpdates Set @@ -25,6 +26,12 @@ func (onConflict OnConflict) Build(builder Builder) { } builder.WriteString(`) `) } + + if len(onConflict.TargetWhere.Exprs) > 0 { + builder.WriteString(" WHERE ") + onConflict.TargetWhere.Build(builder) + builder.WriteByte(' ') + } if onConflict.OnConstraint != "" { builder.WriteString("ON CONSTRAINT ")