Skip to content

Have pgx.ErrNoRows wrap sql.ErrNoRows #1931

Closed
@jessdwitch

Description

@jessdwitch

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions