From d46bc444ac0f2b4c027e624c10bc8d49ffbe2a2f Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Fri, 10 Jun 2005 16:23:11 +0000 Subject: Implement two new special variables in PL/PgSQL: SQLSTATE and SQLERRM. These contain the SQLSTATE and error message of the current exception, respectively. They are scope-local variables that are only defined in exception handlers (so attempting to reference them outside an exception handler is an error). Update the regression tests and the documentation. Also, do some minor related cleanup: export an unpack_sql_state() function from the backend and use it to unpack a SQLSTATE into a string, and add a free_var() function to pl_exec.c Original patch from Pavel Stehule, review by Neil Conway. --- doc/src/sgml/plpgsql.sgml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'doc/src') diff --git a/doc/src/sgml/plpgsql.sgml b/doc/src/sgml/plpgsql.sgml index d96c123e21c..c043c78fea3 100644 --- a/doc/src/sgml/plpgsql.sgml +++ b/doc/src/sgml/plpgsql.sgml @@ -1,5 +1,5 @@ @@ -2110,6 +2110,17 @@ END; don't use EXCEPTION without need. + + + Within an exception handler, the SQLSTATE + variable contains the error code that corresponds to the + exception that was raised (refer to for a list of possible error + codes). The SQLERRM variable contains the + error message associated with the exception. These variables are + undefined outside exception handlers. + + Exceptions with UPDATE/INSERT -- cgit v1.2.3