Skip to content
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

How do I know what constraint I just violated? #14

Closed
nickretallack opened this issue Jan 31, 2014 · 3 comments
Closed

How do I know what constraint I just violated? #14

nickretallack opened this issue Jan 31, 2014 · 3 comments

Comments

@nickretallack
Copy link

When I exec a query that violates a constraint, I get an error back, but unfortunately the fields in it seem to be opaque to me. What is most of interest in the error is the name of the constraint that the query violated. Based on this, I could prepare a friendly message to the user explaining what the problem with their request is.

I suppose I could parse the error string given by Error(), but if there were a friendlier way to get at that constraint name, that would be nice.

@nickretallack
Copy link
Author

Oh cool. I inspected an error and found the info I was looking for.

err.(*pq.Error).Constraint

@bmizerany
Copy link
Owner

Can we close this? Also, pq is now at lib/pq.

@bmizerany
Copy link
Owner

Closing. Please re-post at http://github.com/lib/pq if there is still a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants