-
Notifications
You must be signed in to change notification settings - Fork 850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Row.Err method #950
base: master
Are you sure you want to change the base?
Add Row.Err method #950
Conversation
I realize this is a somewhat breaking change since Row is an interface (though the doc comment explicitly allows for adding methods). If this is deemed too breaking, it would be great to add the method without adding it to the interface so consumers can define their own interface and convert |
Expose Rows.Err as a method on Row, to allow for easily checking whether the query returned an error without calling Scan.
What is the reason for this? Part of the advantage of |
My use case is for a library that provides instrumentation. It wraps the I'd like to collect this information as soon as the query completes (to accurately compute duration) and even if the client doesn't call I previously used |
There's no guarantee that will do what you want (though it usually will). It so happens that what you are trying to do will usually work because PG tries to bundle messages together for syscall and network efficiency and pgx reads up to the The only way to know for sure that a query is complete and did not have an error is close
This same limitation would apply when using |
That's good feedback, thanks. In practice it's more intended for measuring for how long the application goroutine is blocked on reading from the database, and not the actual query time, so it's probably good enough for now, but it's worth considering the approach and doing something more sophisticated. It still seems useful to me for a library to check for an error without calling |
Hey @jackc, thoughts on this? Would be great to get it in if possible. |
As is, the only error this could detect would would be sending the query and that is all the time it would measure as well. I think both For these to be accurate, |
Expose Rows.Err as a method on Row, to allow for easily checking
whether the query returned an error without calling Scan.