Implement two new special variables in PL/PgSQL: SQLSTATE and SQLERRM.

Neil Conway <neilc@samurai.com>

Commit: d46bc444ac0f2b4c027e624c10bc8d49ffbe2a2f
Author: Neil Conway <neilc@samurai.com>
Date: 2005-06-10T16:23:11Z
Releases: 8.1.0
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.

Files