fix postgres
Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
parent
1e50bd8705
commit
5b92ebc141
|
@ -58,7 +58,7 @@ func (statement *Statement) GenUpsertSQL(doUpdate bool, columns []string, args [
|
||||||
}
|
}
|
||||||
|
|
||||||
switch statement.dialect.URI().DBType {
|
switch statement.dialect.URI().DBType {
|
||||||
case schemas.SQLITE, schemas.POSTGRES:
|
case schemas.SQLITE:
|
||||||
write(" ON CONFLICT DO ")
|
write(" ON CONFLICT DO ")
|
||||||
if doUpdate {
|
if doUpdate {
|
||||||
write("UPDATE SET ", updateColumns[0], " = excluded.", updateColumns[0])
|
write("UPDATE SET ", updateColumns[0], " = excluded.", updateColumns[0])
|
||||||
|
@ -68,6 +68,24 @@ func (statement *Statement) GenUpsertSQL(doUpdate bool, columns []string, args [
|
||||||
} else {
|
} else {
|
||||||
write("NOTHING")
|
write("NOTHING")
|
||||||
}
|
}
|
||||||
|
case schemas.POSTGRES:
|
||||||
|
if doUpdate {
|
||||||
|
for _, index := range table.Indexes {
|
||||||
|
if index.Type != schemas.UniqueType {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
write(" ON CONFLICT (", quote(index.Cols[0]))
|
||||||
|
for _, col := range index.Cols[1:] {
|
||||||
|
write(", ", quote(col))
|
||||||
|
}
|
||||||
|
write(") DO UPDATE SET ", updateColumns[0], " = excluded.", updateColumns[0])
|
||||||
|
for _, column := range updateColumns[1:] {
|
||||||
|
write(", ", column, " = excluded.", column)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
write(" ON CONFLICT DO NOTHING")
|
||||||
|
}
|
||||||
case schemas.MYSQL:
|
case schemas.MYSQL:
|
||||||
if doUpdate {
|
if doUpdate {
|
||||||
// FIXME: mysql >= 8.0.19 should use table alias
|
// FIXME: mysql >= 8.0.19 should use table alias
|
||||||
|
|
Loading…
Reference in New Issue