Skip to content

Commit

Permalink
Merge pull request #1316 from atzedus/revert-pr-1290
Browse files Browse the repository at this point in the history
Revert PR #1290, closes #1312
  • Loading branch information
stephenafamo authored Oct 17, 2023
2 parents 644d45d + 77c94e3 commit 8385710
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion drivers/sqlboiler-psql/driver/override/main/17_upsert.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ func (o *{{$alias.UpSingular}}) Upsert({{if .NoContext}}exec boil.Executor{{else
}

conflict := conflictColumns
if len(conflict) == 0 {
if len(conflict) == 0 && updateOnConflict && len(update) != 0 {
if len({{$alias.DownSingular}}PrimaryKeyColumns) == 0 {
return errors.New("{{.PkgName}}: unable to upsert {{.Table.Name}}, could not build conflict column list")
}

conflict = make([]string, len({{$alias.DownSingular}}PrimaryKeyColumns))
copy(conflict, {{$alias.DownSingular}}PrimaryKeyColumns)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ func buildUpsertQueryPostgres(dia drivers.Dialect, tableName string, updateOnCon
columns,
)

buf.WriteByte('(')
buf.WriteString(strings.Join(conflict, ", "))
if len(conflict) != 0 {
buf.WriteByte('(')
buf.WriteString(strings.Join(conflict, ", "))
buf.WriteString(") ")
}

if !updateOnConflict || len(update) == 0 {
buf.WriteString(") DO NOTHING")
buf.WriteString("DO NOTHING")
} else {
buf.WriteString(") DO UPDATE SET ")
buf.WriteString("DO UPDATE SET ")
for i, v := range update {
if len(v) == 0 {
Expand Down

0 comments on commit 8385710

Please sign in to comment.