DO $$
try:
plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table_name => 'users_tab', _datatype_name => 'user_type')")
-except Exception, e:
+except Exception as e:
plpy.info(e.spidata)
raise e
$$ LANGUAGE plpythonu;
DO $$
try:
plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table_name = 'users_tab', datatype_name = 'user_type')
-except Exception, e:
+except Exception as e:
plpy.info('sqlstate: %s, hint: %s, table_name: %s, datatype_name: %s' % (e.sqlstate, e.hint, e.table_name, e.datatype_name))
raise e
$$ LANGUAGE plpythonu;
q = "SELECT fname FROM users WHERE lname = $1"
try:
SD["plan"] = plpy.prepare(q, [ "test" ])
- except plpy.SPIError, ex:
+ except plpy.SPIError as ex:
plpy.notice(str(ex))
return None
rv = plpy.execute(SD["plan"], [ a ])
q = "SELECT fname FROM users WHERE lname = $1"
try:
SD["plan"] = plpy.prepare(q, [ "test" ])
- except plpy.SPIError, ex:
+ except plpy.SPIError as ex:
plpy.error(str(ex))
rv = plpy.execute(SD["plan"], [ a ])
if len(rv):
from plpy import spiexceptions
try:
plpy.execute("insert into specific values (%s)" % (i or "NULL"));
-except spiexceptions.NotNullViolation, e:
+except spiexceptions.NotNullViolation as e:
plpy.notice("Violated the NOT NULL constraint, sqlstate %s" % e.sqlstate)
-except spiexceptions.UniqueViolation, e:
+except spiexceptions.UniqueViolation as e:
plpy.notice("Violated the UNIQUE constraint, sqlstate %s" % e.sqlstate)
$$ LANGUAGE plpythonu;
SELECT specific_exception(2);
import re
import string
import time
-except Exception, ex:
+except Exception as ex:
plpy.notice("import failed -- %s" % str(ex))
return "failed, that wasn''t supposed to happen"
return "succeeded, as expected"'
try:
assert a1 == args[0]
return False
-except NameError, e:
+except NameError as e:
assert e.args[0].find("a1") > -1
return True
$$ LANGUAGE plpythonu;
try:
rv = plpy.execute(SD["myplan"], [a])
return "there are " + str(rv[0]["count"]) + " " + str(a) + "s"
-except Exception, ex:
+except Exception as ex:
plpy.error(str(ex))
return None
'
try:
rv = SD["myplan"].execute([a])
return "there are " + str(rv[0]["count"]) + " " + str(a) + "s"
-except Exception, ex:
+except Exception as ex:
plpy.error(str(ex))
return None
'
rv = plpy.execute(SD["myplan"])
if len(rv):
return rv[0]["count"]
-except Exception, ex:
+except Exception as ex:
plpy.error(str(ex))
return None
'
with plpy.subtransaction():
plpy.execute("INSERT INTO subtransaction_tbl VALUES (3)")
plpy.execute("error")
- except plpy.SPIError, e:
+ except plpy.SPIError as e:
if not swallow:
raise
plpy.notice("Swallowed %s(%r)" % (e.__class__.__name__, e.args[0]))
import marshal
try:
return marshal.loads(x)
-except ValueError, e:
+except ValueError as e:
return 'FAILED: ' + str(e)
$$ LANGUAGE plpythonu;
SELECT test_type_unmarshal(x) FROM test_type_marshal() x;
pgregress-python3-mangle:
$(MKDIR_P) sql/python3 expected/python3 results/python3
for file in $(patsubst %,$(srcdir)/sql/%.sql,$(REGRESS_PLPYTHON3_MANGLE)) $(patsubst %,$(srcdir)/expected/%*.out,$(REGRESS_PLPYTHON3_MANGLE)); do \
- sed -e 's/except \([[:alpha:]][[:alpha:].]*\), *\([[:alpha:]][[:alpha:]]*\):/except \1 as \2:/g' \
+ sed \
-e "s/<type 'exceptions\.\([[:alpha:]]*\)'>/<class '\1'>/g" \
-e "s/<type 'long'>/<class 'int'>/g" \
-e "s/\([0-9][0-9]*\)L/\1/g" \
DO $$
try:
plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table_name => 'users_tab', _datatype_name => 'user_type')")
-except Exception, e:
+except Exception as e:
plpy.info(e.spidata)
raise e
$$ LANGUAGE plpythonu;
DO $$
try:
plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table_name = 'users_tab', datatype_name = 'user_type')
-except Exception, e:
+except Exception as e:
plpy.info('sqlstate: %s, hint: %s, table_name: %s, datatype_name: %s' % (e.sqlstate, e.hint, e.table_name, e.datatype_name))
raise e
$$ LANGUAGE plpythonu;
q = "SELECT fname FROM users WHERE lname = $1"
try:
SD["plan"] = plpy.prepare(q, [ "test" ])
- except plpy.SPIError, ex:
+ except plpy.SPIError as ex:
plpy.notice(str(ex))
return None
rv = plpy.execute(SD["plan"], [ a ])
q = "SELECT fname FROM users WHERE lname = $1"
try:
SD["plan"] = plpy.prepare(q, [ "test" ])
- except plpy.SPIError, ex:
+ except plpy.SPIError as ex:
plpy.error(str(ex))
rv = plpy.execute(SD["plan"], [ a ])
if len(rv):
from plpy import spiexceptions
try:
plpy.execute("insert into specific values (%s)" % (i or "NULL"));
-except spiexceptions.NotNullViolation, e:
+except spiexceptions.NotNullViolation as e:
plpy.notice("Violated the NOT NULL constraint, sqlstate %s" % e.sqlstate)
-except spiexceptions.UniqueViolation, e:
+except spiexceptions.UniqueViolation as e:
plpy.notice("Violated the UNIQUE constraint, sqlstate %s" % e.sqlstate)
$$ LANGUAGE plpythonu;
import re
import string
import time
-except Exception, ex:
+except Exception as ex:
plpy.notice("import failed -- %s" % str(ex))
return "failed, that wasn''t supposed to happen"
return "succeeded, as expected"'
try:
assert a1 == args[0]
return False
-except NameError, e:
+except NameError as e:
assert e.args[0].find("a1") > -1
return True
$$ LANGUAGE plpythonu;
try:
rv = plpy.execute(SD["myplan"], [a])
return "there are " + str(rv[0]["count"]) + " " + str(a) + "s"
-except Exception, ex:
+except Exception as ex:
plpy.error(str(ex))
return None
'
try:
rv = SD["myplan"].execute([a])
return "there are " + str(rv[0]["count"]) + " " + str(a) + "s"
-except Exception, ex:
+except Exception as ex:
plpy.error(str(ex))
return None
'
rv = plpy.execute(SD["myplan"])
if len(rv):
return rv[0]["count"]
-except Exception, ex:
+except Exception as ex:
plpy.error(str(ex))
return None
'
with plpy.subtransaction():
plpy.execute("INSERT INTO subtransaction_tbl VALUES (3)")
plpy.execute("error")
- except plpy.SPIError, e:
+ except plpy.SPIError as e:
if not swallow:
raise
plpy.notice("Swallowed %s(%r)" % (e.__class__.__name__, e.args[0]))
import marshal
try:
return marshal.loads(x)
-except ValueError, e:
+except ValueError as e:
return 'FAILED: ' + str(e)
$$ LANGUAGE plpythonu;
close($handle);
do
{
- s/except ([[:alpha:]][[:alpha:].]*), *([[:alpha:]][[:alpha:]]*):/except $1 as $2:/g;
s/<type 'exceptions\.([[:alpha:]]*)'>/<class '$1'>/g;
s/<type 'long'>/<class 'int'>/g;
s/([0-9][0-9]*)L/$1/g;