mirror of
https://github.com/hanzoai/sqlbuilder.git
synced 2026-10-01 00:37:42 +00:00
fix #200: PostgreSQL InsertIgnoreInto with subquery doesn't append ON CONFLICT DO NOTHING
This commit is contained in:
@@ -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))
|
||||
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user