Pgx: ErrNoRows in QueryRow from pgxpool

Created on 7 Feb 2020  ·  3Comments  ·  Source: jackc/pgx

I'm using pgxpool, and when I call QueryRow with query returning no rows, comparison with pgx.ErrNoRows is not working:

conn, err := pgxpool.ConnectConfig(context.Background(), cfg)
// ...........................
err := conn.QueryRow(context.Background(), Query).Scan(....)
if err != nil {
    if err == pgx.ErrNoRows {
        return nil
    }
    return err
}

The code above returns err, which is _"no rows in result set"_. But err == pgx.ErrNoRows is false. For now I made dirty fix:
if err.Error() == pgx.ErrNoRows.Error() {
But this doesn't look like good code.

Most helpful comment

I've done more investigation and looks like it's all my fault. Sorry.
Problem was in my imports (I just switched go 1.10 -> 1.13):

import (
    "github.com/jackc/pgx"
    "github.com/jackc/pgx/v4/pgxpool"
)

After I fixed it to

import (
    "github.com/jackc/pgx/v4"
    "github.com/jackc/pgx/v4/pgxpool"
)

problem gone away.
Sorry once again, it's not an issue.

All 3 comments

I am unable to duplicate the issue. I added a successful test case (8c9d1cc15b7307d515d4ff1e1e80776b4b6d1fcc).

I've done more investigation and looks like it's all my fault. Sorry.
Problem was in my imports (I just switched go 1.10 -> 1.13):

import (
    "github.com/jackc/pgx"
    "github.com/jackc/pgx/v4/pgxpool"
)

After I fixed it to

import (
    "github.com/jackc/pgx/v4"
    "github.com/jackc/pgx/v4/pgxpool"
)

problem gone away.
Sorry once again, it's not an issue.

I ran across the exact same issue today. It happens because goimports (or goreturns) will automatically import github.com/jackc/pgx instead of github.com/jackc/pgx/v4.

Is it possible for pgx to inform goimports on how to import it somehow? Not really sure if there's an easy fix for this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bernhardreiter picture bernhardreiter  ·  7Comments

nick-jones picture nick-jones  ·  4Comments

k1ng440 picture k1ng440  ·  5Comments

MOZGIII picture MOZGIII  ·  4Comments

danclive picture danclive  ·  6Comments