pq: No way to see an Insert error from QueryRow()
I want to make an insert into a table with constraints. I also want to get the inserted id value if successful. The problem is if QueryRow() with an INSERT…RETURNING fails, then the error is a rather unhelpful no rows in result set.
The error I want would be something like:
duplicate key violates unique constraint "user_email_unique"
which is the error that’s returned by Exec() but then I don’t get the last inserted id if everything goes well.
About this issue
- Original URL
- State: closed
- Created 11 years ago
- Comments: 27 (14 by maintainers)
Commits related to this issue
- Don't tolerate CommandComplete after Parse + Describe + Sync Commit 13601feaf94cbd2df4a9b0b752150e08c5885f72 introduced this change, (after being reported in issue #77), but the problem does not seem... — committed to lib/pq by johto 11 years ago
- Work around a bug in QueryRow Unfortunately for us, QueryRow ignores errors from the driver's Next, which in our case means that it will happily return ErrNoRows if a run-time error happens while pro... — committed to lib/pq by johto 11 years ago
Just for the record, here’s some code from @chris-baynes to make this a little bit more comfortable, reproduced here incase the Gist disappears: