debugsqlMinor
How can I get a Postgresql error number in psql?
Viewed 0 times
postgresqlcanerrornumberpsqlgethow
Problem
How can I access the numeric code of an error in
For example, in this case I would like to get the value 23503 ("foreign_key_violation") as documented here:
https://www.postgresql.org/docs/current/errcodes-appendix.html
psql?For example, in this case I would like to get the value 23503 ("foreign_key_violation") as documented here:
https://www.postgresql.org/docs/current/errcodes-appendix.html
postgres=# insert into t values('bb');
ERROR: insert or update on table "t" violates foreign key constraint "fd"
-- How can I see the numeric error code here?Solution
You can set the
Alternatively, you can print the SQLSTATE code on demand:
VERBOSITY special variable to sqlstate, which will cause the SQLSTATE code to be printed after any failed statement in the current session:\set VERBOSITY sqlstateAlternatively, you can print the SQLSTATE code on demand:
\echo :LAST_ERROR_SQLSTATECode Snippets
\set VERBOSITY sqlstate\echo :LAST_ERROR_SQLSTATEContext
StackExchange Database Administrators Q#318487, answer score: 6
Revisions (0)
No revisions yet.