pgx.ErrNoRows does not match err returned by query
Asked Answered
P

0

7

New at pgx. Using pgxpool. I have a simple Query

var result string
err := Conn.QueryRow(context.Background(),
    `SELECT name FROM table WHERE id=1000`).Scan(&result)

if err != nil {
    if err == pgx.ErrNoRows {
        fmt.Println("No Rows")
        fmt.Println(err)
    } else {
        fmt.Println("Other Error")
        fmt.Println(err)
    }
}

I am never getting "No Rows" even though No Rows are actually being returned. The err is ALWAYS "no rows in result set" but it never matches pgx.ErrNoRows, as I understood they are supposed to be the same.

On checking Types, pgx.ErrNoRows = *errors.fundamental while err = *xerrors.errorString.

What am I doing or assuming worng?

EDIT:

As @mkopriva mentioned below, the Problem is goimport automatically imports the wrong pgx, it needs to be "github.com/jackc/pgx/v4"

Practicable answered 3/10, 2020 at 14:42 Comment(2)
see github.com/jackc/pgx/issues/677 maybe it'll helpRadie
@Radie Thanks a Lot. Thats what the issue was exactly. pgx/v4 was needed instead of pgx. CheersPracticable

© 2022 - 2024 — McMap. All rights reserved.