summaryrefslogtreecommitdiff
path: root/src/pl/plpython/sql/plpython_error.sql
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2011-02-02 22:06:10 +0200
committerPeter Eisentraut <peter_e@gmx.net>2011-02-02 22:06:10 +0200
commit0c5933d0104c1788479592a84cca53da357381f9 (patch)
treef177882aa761e677620b820e6dbb214b5ba9e0ae /src/pl/plpython/sql/plpython_error.sql
parentc73fe72e2735d20aa132640d8fab4e0eca1ced95 (diff)
Wrap PL/Python SPI calls into subtransactions
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
Diffstat (limited to 'src/pl/plpython/sql/plpython_error.sql')
-rw-r--r--src/pl/plpython/sql/plpython_error.sql22
1 files changed, 22 insertions, 0 deletions
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();