OSDN Git Service

Implement two new special variables in PL/PgSQL: SQLSTATE and SQLERRM.
authorNeil Conway <neilc@samurai.com>
Fri, 10 Jun 2005 16:23:11 +0000 (16:23 +0000)
committerNeil Conway <neilc@samurai.com>
Fri, 10 Jun 2005 16:23:11 +0000 (16:23 +0000)
commitd46bc444ac0f2b4c027e624c10bc8d49ffbe2a2f
treea67d32556ae2e472c90963ee5ec63992c4e50149
parent1a61896189c54dbbb63973d45f59c73fd2f4b44c
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
src/backend/utils/error/elog.c
src/include/utils/elog.h
src/pl/plpgsql/src/gram.y
src/pl/plpgsql/src/pl_comp.c
src/pl/plpgsql/src/pl_exec.c
src/pl/plpgsql/src/pl_funcs.c
src/pl/plpgsql/src/plpgsql.h
src/test/regress/expected/plpgsql.out
src/test/regress/sql/plpgsql.sql