Open tcurdt opened 4 years ago
As of right now, that's probably your best bet. It might be worth checking with your sql driver (github.com/lib/pq
I assume) to see if they have sentinel errors or something to compare against or type check with. Or maybe you can add a PR. Something like if dupErr, ok := err.(pq.DuplicateKey); ok {
would be helpful in a lot of scenarios.
err := dbm.Insert(foo)
if pqerror, _ := err.(*pq.Error); pqerror.Code == "23505" {
err := dbm.SelectOne(f, "select * from foo where a=$1 and b=$2", a, b)
if err != nil {
}
}
Errors from pq expose the postgres error code. The postgres error code for duplicate key violation is 23505
which can be found from this table https://www.postgresql.org/docs/current/errcodes-appendix.html
I am currently using this to
Is there a better way to handle a failed uniq constraint?