diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2011-11-24 17:18:43 +0200 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2011-11-24 17:18:43 +0200 |
commit | f21fc7f9fc63ff86d7d77d352ae274b6e2b6e09e (patch) | |
tree | 04b60697b3d4cb694b544dca4a008d3f687c337f /src/pl/plpython/sql/plpython_error.sql | |
parent | 5df1403b0f2b44235c8f401bd49dab9a8cf6bf90 (diff) | |
download | postgresql-f21fc7f9fc63ff86d7d77d352ae274b6e2b6e09e.tar.gz postgresql-f21fc7f9fc63ff86d7d77d352ae274b6e2b6e09e.zip |
Preserve SQLSTATE when an SPI error is propagated through PL/python
exception handler. This was a regression in 9.1, when the capability
to catch specific SPI errors was added, so backpatch to 9.1.
Mika Eloranta, with some editing by Jan UrbaĆski.
Diffstat (limited to 'src/pl/plpython/sql/plpython_error.sql')
-rw-r--r-- | src/pl/plpython/sql/plpython_error.sql | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/pl/plpython/sql/plpython_error.sql b/src/pl/plpython/sql/plpython_error.sql index 4add6aaf05c..502bbec38f4 100644 --- a/src/pl/plpython/sql/plpython_error.sql +++ b/src/pl/plpython/sql/plpython_error.sql @@ -257,6 +257,26 @@ SELECT specific_exception(2); SELECT specific_exception(NULL); SELECT specific_exception(2); +/* SPI errors in PL/Python functions should preserve the SQLSTATE value + */ +CREATE FUNCTION python_unique_violation() RETURNS void AS $$ +plpy.execute("insert into specific values (1)") +plpy.execute("insert into specific values (1)") +$$ LANGUAGE plpythonu; + +CREATE FUNCTION catch_python_unique_violation() RETURNS text AS $$ +begin + begin + perform python_unique_violation(); + exception when unique_violation then + return 'ok'; + end; + return 'not reached'; +end; +$$ language plpgsql; + +SELECT catch_python_unique_violation(); + /* manually starting subtransactions - a bad idea */ CREATE FUNCTION manual_subxact() RETURNS void AS $$ |