bun
bun copied to clipboard
Upsert with `RETURNING("*")` and `ON CONFLICT` doesn't return `sql.ErrNoRows`
Hello, thank you for the great job with bun.
I have come across a scenario which may be a bug/regression from go-pg
.
With go-pg
, performing an UPSERT
with a RETURNING
clause would return pg.ErrNoRows
in the event of a DB conflict. Which allowed having a pattern like so:
if _, err := db.Model(&model).OnConflict("(name) DO NOTHING").Returning("*").Insert(); err != nil {
if err == pg.ErrNoRows {
// Conflict found
return nil, fmt.Errorf("duplicate data")
}
As per the migrating to go-pg docs, pg.ErrNoRows
is replaced by sql.ErrNoRows
, however result, err := db.NewInsert().Model(&model).Ignore().Returning("*").Exec(ctx)
doesn't appear to return any error at all when there is a conflict but instead returns sql.Result
with 0 RowsAffected()
.
Is this an intended behaviour?
@vmihailenco is this valid issue?
Answered in #752