From 0c5933d0104c1788479592a84cca53da357381f9 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 2 Feb 2011 22:06:10 +0200 Subject: Wrap PL/Python SPI calls into subtransactions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows the language-specific try/catch construct to catch and handle exceptions arising from SPI calls, matching the behavior of other PLs. As an additional bonus you no longer get all the ugly "unrecognized error in PLy_spi_execute_query" errors. Jan UrbaƄski, reviewed by Steve Singer --- src/pl/plpython/sql/plpython_error.sql | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/pl/plpython/sql/plpython_error.sql') diff --git a/src/pl/plpython/sql/plpython_error.sql b/src/pl/plpython/sql/plpython_error.sql index 6509257b24d..7861cd61a2f 100644 --- a/src/pl/plpython/sql/plpython_error.sql +++ b/src/pl/plpython/sql/plpython_error.sql @@ -130,3 +130,25 @@ return None LANGUAGE plpythonu; SELECT valid_type('rick'); + +/* manually starting subtransactions - a bad idea + */ +CREATE FUNCTION manual_subxact() RETURNS void AS $$ +plpy.execute("savepoint save") +plpy.execute("create table foo(x integer)") +plpy.execute("rollback to save") +$$ LANGUAGE plpythonu; + +SELECT manual_subxact(); + +/* same for prepared plans + */ +CREATE FUNCTION manual_subxact_prepared() RETURNS void AS $$ +save = plpy.prepare("savepoint save") +rollback = plpy.prepare("rollback to save") +plpy.execute(save) +plpy.execute("create table foo(x integer)") +plpy.execute(rollback) +$$ LANGUAGE plpythonu; + +SELECT manual_subxact_prepared(); -- cgit v1.2.3