Skip to content

Commit

Permalink
Merge pull request #335 from BillBuilt/on-conflict-do-nothing-without…
Browse files Browse the repository at this point in the history
…-conflict-target

ON CONFLICT DO NOTHING without a conflict target is valid SQL
  • Loading branch information
go-jet authored Mar 24, 2024
2 parents 1b63280 + 0d250f5 commit 60d8f15
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion postgres/clause.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (o *onConflictClause) DO_UPDATE(action conflictAction) InsertStatement {
}

func (o *onConflictClause) Serialize(statementType jet.StatementType, out *jet.SQLBuilder, options ...jet.SerializeOption) {
if len(o.indexExpressions) == 0 && o.constraint == "" {
if len(o.indexExpressions) == 0 && o.constraint == "" && o.do != jet.Keyword("DO NOTHING") {
return
}

Expand Down
3 changes: 2 additions & 1 deletion postgres/clause_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ func TestOnConflict(t *testing.T) {

onConflict := &onConflictClause{}
onConflict.DO_NOTHING()
assertClauseSerialize(t, onConflict, "")
assertClauseSerialize(t, onConflict, `
ON CONFLICT DO NOTHING`)

onConflict = &onConflictClause{indexExpressions: ColumnList{table1ColBool}}
onConflict.DO_NOTHING()
Expand Down

0 comments on commit 60d8f15

Please sign in to comment.