fix #200: PostgreSQL InsertIgnoreInto with subquery doesn't append ON CONFLICT DO NOTHING

This commit is contained in:
Huan Du
2025-06-13 01:05:33 +08:00
parent d882448972
commit e9d31b7960
2 changed files with 13 additions and 4 deletions
+1 -4
View File
@@ -197,10 +197,7 @@ func (ib *InsertBuilder) BuildWithFlavor(flavor Flavor, initialArg ...interface{
buf.WriteString(ib.sbHolder)
ib.injection.WriteTo(buf, insertMarkerAfterSelect)
return ib.args.CompileWithFlavor(buf.String(), flavor, initialArg...)
}
if len(ib.values) > 0 {
} else if len(ib.values) > 0 {
buf.WriteLeadingString("VALUES ")
values := make([]string, 0, len(ib.values))
+12
View File
@@ -305,3 +305,15 @@ func TestInsertBuilderGetFlavor(t *testing.T) {
flavor = ibClick.Flavor()
a.Equal(ClickHouse, flavor)
}
func TestIssue200(t *testing.T) {
a := assert.New(t)
ib := PostgreSQL.NewInsertBuilder()
ib.InsertIgnoreInto("table")
ib.Cols("data")
sb := ib.Select("id", "data").From("table")
sb.Where(sb.Equal("id", 1))
query, _ := ib.Build()
a.Equal(query, "INSERT INTO table (data) SELECT id, data FROM table WHERE id = $1 ON CONFLICT DO NOTHING")
}