Skip to content

Commit

Permalink
Ignore empty errors on postgres upsert fail
Browse files Browse the repository at this point in the history
- Postgres's behavior when there is no update is that there is an
  ErrNoRows thrown back, which we can safely ignore since the only time
  this can happen in postgres's case is under this circumstance since
  there's no race unlike the mysql upsert code.
- Fix #84
  • Loading branch information
aarondl committed Jan 6, 2017
1 parent 4ae9336 commit 22f7a45
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion templates/17_upsert.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,14 @@ func (o *{{$tableNameSingular}}) Upsert(exec boil.Executor, {{if ne .DriverName
{{- else}}
if len(cache.retMapping) != 0 {
err = exec.QueryRow(cache.query, vals...).Scan(returns...)
if err == sql.ErrNoRows {
err = nil // Postgres doesn't return anything when there's no update
}
} else {
_, err = exec.Exec(cache.query, vals...)
}
if err != nil {
return errors.Wrap(err, "{{.PkgName}}: unable to upsert for {{.Table.Name}}")
return errors.Wrap(err, "{{.PkgName}}: unable to upsert {{.Table.Name}}")
}
{{- end}}

Expand Down

0 comments on commit 22f7a45

Please sign in to comment.