Skip to content

Commit 746784b

Browse files
committed
fix #200: PostgreSQL InsertIgnoreInto with subquery doesn't append ON CONFLICT DO NOTHING
1 parent fd0b5a9 commit 746784b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

insert.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,7 @@ func (ib *InsertBuilder) BuildWithFlavor(flavor Flavor, initialArg ...interface{
197197
buf.WriteString(ib.sbHolder)
198198

199199
ib.injection.WriteTo(buf, insertMarkerAfterSelect)
200-
return ib.args.CompileWithFlavor(buf.String(), flavor, initialArg...)
201-
}
202-
203-
if len(ib.values) > 0 {
200+
} else if len(ib.values) > 0 {
204201
buf.WriteLeadingString("VALUES ")
205202
values := make([]string, 0, len(ib.values))
206203

insert_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,15 @@ func TestInsertBuilderGetFlavor(t *testing.T) {
305305
flavor = ibClick.Flavor()
306306
a.Equal(ClickHouse, flavor)
307307
}
308+
309+
func TestIssue200(t *testing.T) {
310+
a := assert.New(t)
311+
ib := PostgreSQL.NewInsertBuilder()
312+
ib.InsertIgnoreInto("table")
313+
ib.Cols("data")
314+
sb := ib.Select("id", "data").From("table")
315+
sb.Where(sb.Equal("id", 1))
316+
317+
query, _ := ib.Build()
318+
a.Equal(query, "INSERT INTO table (data) SELECT id, data FROM table WHERE id = $1 ON CONFLICT DO NOTHING")
319+
}

0 commit comments

Comments
 (0)