pgx icon indicating copy to clipboard operation
pgx copied to clipboard

Have pgx.ErrNoRows wrap sql.ErrNoRows

Open jessdwitch opened this issue 11 months ago • 1 comments

Is your feature request related to a problem? Please describe. I've got a SQL consuming application that uses a different database driver based on build target. My check for an empty result uses errors.Is(err, sql.ErrNoRows), but this doesn't work with pgx, since it returns pgx.ErrNoRows.

Describe the solution you'd like Since errors.Is unwraps errors, having pgx.ErrNoRows unwrap into a sql.ErrNoRows would make Is (and as a side-benefit, As) work for both pgx and sql errors, while still returning pgx.ErrNoRows. This can be done while keeping the string content and current behavior of errors.Is(err, pgx.ErrNoRows)

Describe alternatives you've considered Having my DB implementations wrap the pgx-returned errors with an application-specific equivalent of "no rows" before leaving the DB interface and checking against that works (and is what I'm doing currently), but requires extra boilerplate.

I could also eschew the pgx interface and just use database/sql, but I'm using pgxpool, and I'm not sure if there's a way to access the native DB interface from a *pgxpool.Pool.

Additional context None that I can think of.

jessdwitch avatar Mar 06 '24 18:03 jessdwitch

Seems reasonable. 👍

jackc avatar Mar 09 '24 17:03 jackc