Closed darylhjd closed 4 months ago
https://github.com/go-jet/jet/blob/33333585e9571ee4375c1a6ee99acff129c801ba/internal/jet/statement.go#L21-L24
Only if the destination is a pointer to a struct ErrNoRows
is returned.
If the destination is a slice, you can check if there were any updates, by checking the slice length:
if len(dest) == 0 {
// no updates
}
Thanks for the reply!
Is this a deliberate design choice for compatibility with multiple database implementations (Postgres, MySQL, etc...)? Because I personally think the behaviour of errors should be type-agnostic for more predictable behaviour.
Yeah, it's a mistake made at the begging and has remained until now. There is a plan to deprecate the current Query
and QueryContext
and create two new ones, QueryScanOne
and QueryScanMany
, but there is always some higher priority features. Maybe we can squeeze it into the next release.
Describe the bug
ErrNoRows
error is not returned when update is skipped during an upsert with PostgreSQL.Code snippet Using the following query:
where classes has the following schema:
When a row with the same
code
,year
,semester
, andprogramme
fields is going to be inserted:ON CONFLICT
will attempt to DO UPDATEDO UPDATE
will not set the new field because theprogramme
field has the same value according toWHERE
clause.RETURNING
returns no rows (destination is nil).However, when doing
QueryContext
on the query, noErrNoRows
error is returned even though there is no result.Expected behavior Since the update is skipped and no rows are returned from the resulting query, I expect
ErrNoRows
to be returned but this is not the case. Not sure if this is expected or a bug.