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.
This commit is contained in:
Heikki Linnakangas
2011-11-24 17:18:43 +02:00
parent 5df1403b0f
commit f21fc7f9fc
4 changed files with 72 additions and 6 deletions

View File

@ -351,6 +351,28 @@ CONTEXT: PL/Python function "specific_exception"
(1 row)
/* 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();
catch_python_unique_violation
-------------------------------
ok
(1 row)
/* manually starting subtransactions - a bad idea
*/
CREATE FUNCTION manual_subxact() RETURNS void AS $$

View File

@ -351,6 +351,28 @@ CONTEXT: PL/Python function "specific_exception"
(1 row)
/* 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();
catch_python_unique_violation
-------------------------------
ok
(1 row)
/* manually starting subtransactions - a bad idea
*/
CREATE FUNCTION manual_subxact() RETURNS void AS $$