Using the database/sql
package in go for things like sql.Exec
will return dynamically generated, unreferenced errors such as
"Error 1062: Duplicate entry '192' for key 'id'"
The problem is that it can also return errors such as
"Error 1146: Table 'tbl' doesn't exist"
From the same call to sql.Exec
How can I tell the difference between these two errors without
- String comparison, or
- Pattern matching for error code
Or are those idiomatic viable solutions for this problem?