I\'m trying to delete a database using the postgres driver (lib/pq) by doing a:
db.Exec(\"DROP DATABASE dbName;\")
But I\'d like to do a differe
The lib/pq package may return errors of type *pq.Error, which is a struct. If it does, you may use all its fields to inspect for details of the error.
This is how it can be done:
if err, ok := err.(*pq.Error); ok {
// Here err is of type *pq.Error, you may inspect all its fields, e.g.:
fmt.Println("pq error:", err.Code.Name())
}
pq.Error
has the following fields:
type Error struct {
Severity string
Code ErrorCode
Message string
Detail string
Hint string
Position string
InternalPosition string
InternalQuery string
Where string
Schema string
Table string
Column string
DataTypeName string
Constraint string
File string
Line string
Routine string
}
The meaning and possible values of these fields are Postres specific and the full list can be found here: Error and Notice Message Fields