From cd37bb78599dcf24cd22a124ce9174b5e2a76880 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 25 Mar 2016 16:54:52 -0400 Subject: Improve PL/Tcl errorCode facility by providing decoded name for SQLSTATE. We don't really want to encourage people to write numeric SQLSTATEs in programs; that's unreadable and error-prone. Copy plpgsql's infrastructure for converting between SQLSTATEs and exception names shown in Appendix A, and modify examples in tests and documentation to do it that way. --- doc/src/sgml/pltcl.sgml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/pltcl.sgml b/doc/src/sgml/pltcl.sgml index 1ff9b96fa52..805cc89dc99 100644 --- a/doc/src/sgml/pltcl.sgml +++ b/doc/src/sgml/pltcl.sgml @@ -813,14 +813,16 @@ CREATE EVENT TRIGGER tcl_a_snitch ON ddl_command_start EXECUTE PROCEDURE tclsnit word is POSTGRES, the second word is the Postgres version number, and additional words are field name/value pairs providing detailed information about the error. - Fields message and SQLSTATE (the error code - shown in ) are always supplied. + Fields SQLSTATE, condition, + and message are always supplied + (the first two represent the error code and condition name as shown + in ). Fields that may be present include detail, hint, context, schema, table, column, datatype, constraint, statement, cursor_position, - filename, lineno and + filename, lineno, and funcname. @@ -832,7 +834,7 @@ CREATE EVENT TRIGGER tcl_a_snitch ON ddl_command_start EXECUTE PROCEDURE tclsnit if {[catch { spi_exec $sql_command }]} { if {[lindex $::errorCode 0] == "POSTGRES"} { array set errorArray $::errorCode - if {$errorArray(SQLSTATE) == "42P01"} { # UNDEFINED_TABLE + if {$errorArray(condition) == "undefined_table"} { # deal with missing table } else { # deal with some other type of SQL error -- cgit v1.2.3