Tuesday, January 21, 2025
HomeGolangDarshan Hiranandani : Dealing with NoRowsError for A number of Rows in...

Darshan Hiranandani : Dealing with NoRowsError for A number of Rows in pgx with pgxpool – Getting Assist


Hiya everybody,

I’m Darshan Hiranandani, engaged on a challenge utilizing pgxpool to question a PostgreSQL database, and I’ve come throughout a difficulty when dealing with queries that will return no rows. Right here’s the state of affairs:

I’m utilizing the question:

SELECT * FROM invoices WHERE user_id = $1, id

This question returns a pgx.Rows sort, which incorporates the outcomes of the question together with any related error. The difficulty is that pgx.Question() doesn’t return an error for when no rows are discovered, which leaves me with no method to differentiate between an empty end result and an precise error.

I perceive that pgx.QueryRow() mixed with pgxscan.ScanOne() can return a NoRowsError, however this solely works once you’re anticipating a single row. In my case, I must return a number of rows, so this doesn’t match my use case.

From what I’ve gathered, I must be utilizing Rows.Subsequent() to verify if the subsequent row exists, and if not, it is going to return false. The issue is that when rows are returned, I’m uncertain of the subsequent steps.

Has anybody encountered this challenge and located a great way to deal with it whereas working with a number of rows in pgx? Any recommendation or examples can be vastly appreciated.

Thanks upfront!
Regards
Darshan Hiranandani

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments