ERROR cannot catch plpy.SPIError
BaiShaoqi opened this issue · 2 comments
BaiShaoqi commented
Expected behavior
NOTICE: type "test" does not exist
CONTEXT: PL/Python function "invalid_type_caught"
invalid_type_caught
---------------------
(1 row)
Actual behavior
ERROR: type "test" does not exist
Step to reproduce the behavior
CREATE TABLE users (
fname text not null,
lname text not null,
username text,
userid serial,
PRIMARY KEY(lname, fname)
) ;
INSERT INTO users (fname, lname, username) VALUES ('jane', 'doe', 'j_doe');
INSERT INTO users (fname, lname, username) VALUES ('john', 'doe', 'johnd');
INSERT INTO users (fname, lname, username) VALUES ('willem', 'doe', 'w_doe');
INSERT INTO users (fname, lname, username) VALUES ('rick', 'smith', 'slash');
CREATE FUNCTION invalid_type_caught(a text) RETURNS text
AS $$
# container: plc_python_shared
if "plan" not in SD:
q = "SELECT fname FROM users WHERE lname = $1"
try:
SD["plan"] = plpy.prepare(q, [ "test" ])
except plpy.SPIError, ex:
plpy.notice(str(ex))
return None
rv = plpy.execute(SD["plan"], [ a ])
if len(rv):
return rv[0]["fname"]
return None
$$ LANGUAGE plcontainer;
SELECT invalid_type_caught('rick');