plpython: Remove regression test infrastructure for Python 2.

Since 19252e8ec9 we reject Python 2 during build configuration. Now that the
dust on the buildfarm has settled, remove regression testing infrastructure
dealing with differing output between Python 2 / 3.

Reviewed-By: Peter Eisentraut <peter@eisentraut.org>
Reviewed-By: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/20211031184548.g4sxfe47n2kyi55r@alap3.anarazel.de
This commit is contained in:
Andres Freund 2022-03-07 18:19:56 -08:00
parent 76a29adee7
commit db23464715
60 changed files with 625 additions and 2236 deletions

View File

@ -1,6 +1,4 @@
# Generated subdirectories # Generated subdirectories
/expected/python3/
/log/ /log/
/results/ /results/
/sql/python3/
/tmp_check/ /tmp_check/

View File

@ -10,7 +10,6 @@ EXTENSION = hstore_plpython3u
DATA = hstore_plpython3u--1.0.sql DATA = hstore_plpython3u--1.0.sql
REGRESS = hstore_plpython REGRESS = hstore_plpython
REGRESS_PLPYTHON3_MANGLE := $(REGRESS)
PG_CPPFLAGS = $(python_includespec) -DPLPYTHON_LIBNAME='"plpython$(python_majorversion)"' PG_CPPFLAGS = $(python_includespec) -DPLPYTHON_LIBNAME='"plpython$(python_majorversion)"'
@ -37,9 +36,4 @@ SHLIB_LINK += $(python_libspec) $(python_additional_libs)
endif endif
REGRESS_OPTS += --load-extension=hstore REGRESS_OPTS += --load-extension=hstore
ifeq ($(python_majorversion),2)
REGRESS_OPTS += --load-extension=plpythonu --load-extension=hstore_plpythonu
endif
EXTRA_INSTALL += contrib/hstore EXTRA_INSTALL += contrib/hstore
include $(top_srcdir)/src/pl/plpython/regress-python3-mangle.mk

View File

@ -1,8 +1,8 @@
CREATE EXTENSION hstore_plpython2u CASCADE; CREATE EXTENSION hstore_plpython3u CASCADE;
NOTICE: installing required extension "plpython2u" NOTICE: installing required extension "plpython3u"
-- test hstore -> python -- test hstore -> python
CREATE FUNCTION test1(val hstore) RETURNS int CREATE FUNCTION test1(val hstore) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
assert isinstance(val, dict) assert isinstance(val, dict)
@ -18,7 +18,7 @@ INFO: [('aa', 'bb'), ('cc', None)]
-- the same with the versioned language name -- the same with the versioned language name
CREATE FUNCTION test1n(val hstore) RETURNS int CREATE FUNCTION test1n(val hstore) RETURNS int
LANGUAGE plpython2u LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
assert isinstance(val, dict) assert isinstance(val, dict)
@ -34,7 +34,7 @@ INFO: [('aa', 'bb'), ('cc', None)]
-- test hstore[] -> python -- test hstore[] -> python
CREATE FUNCTION test1arr(val hstore[]) RETURNS int CREATE FUNCTION test1arr(val hstore[]) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
assert(val == [{'aa': 'bb', 'cc': None}, {'dd': 'ee'}]) assert(val == [{'aa': 'bb', 'cc': None}, {'dd': 'ee'}])
@ -48,7 +48,7 @@ SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']);
-- test python -> hstore -- test python -> hstore
CREATE FUNCTION test2(a int, b text) RETURNS hstore CREATE FUNCTION test2(a int, b text) RETURNS hstore
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
val = {'a': a, 'b': b, 'c': None} val = {'a': a, 'b': b, 'c': None}
@ -65,14 +65,14 @@ SELECT test2(1, 'boo');
CREATE OR REPLACE FUNCTION public.test2(a integer, b text) CREATE OR REPLACE FUNCTION public.test2(a integer, b text)
RETURNS hstore RETURNS hstore
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
LANGUAGE plpythonu LANGUAGE plpython3u
AS $function$ AS $function$
val = {'a': a, 'b': b, 'c': None} val = {'a': a, 'b': b, 'c': None}
return val return val
$function$ $function$
-- test python -> hstore[] -- test python -> hstore[]
CREATE FUNCTION test2arr() RETURNS hstore[] CREATE FUNCTION test2arr() RETURNS hstore[]
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
val = [{'a': 1, 'b': 'boo', 'c': None}, {'d': 2}] val = [{'a': 1, 'b': 'boo', 'c': None}, {'d': 2}]
@ -87,7 +87,7 @@ SELECT test2arr();
-- test python -> domain over hstore -- test python -> domain over hstore
CREATE DOMAIN hstore_foo AS hstore CHECK(VALUE ? 'foo'); CREATE DOMAIN hstore_foo AS hstore CHECK(VALUE ? 'foo');
CREATE FUNCTION test2dom(fn text) RETURNS hstore_foo CREATE FUNCTION test2dom(fn text) RETURNS hstore_foo
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
return {'a': 1, fn: 'boo', 'c': None} return {'a': 1, fn: 'boo', 'c': None}
@ -104,7 +104,7 @@ CONTEXT: while creating return value
PL/Python function "test2dom" PL/Python function "test2dom"
-- test as part of prepare/execute -- test as part of prepare/execute
CREATE FUNCTION test3() RETURNS void CREATE FUNCTION test3() RETURNS void
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
rv = plpy.execute("SELECT 'aa=>bb, cc=>NULL'::hstore AS col1") rv = plpy.execute("SELECT 'aa=>bb, cc=>NULL'::hstore AS col1")
@ -131,7 +131,7 @@ SELECT * FROM test1;
(1 row) (1 row)
CREATE FUNCTION test4() RETURNS trigger CREATE FUNCTION test4() RETURNS trigger
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
assert(TD["new"] == {'a': 1, 'b': {'aa': 'bb', 'cc': None}}) assert(TD["new"] == {'a': 1, 'b': {'aa': 'bb', 'cc': None}})

View File

@ -1,9 +1,9 @@
CREATE EXTENSION hstore_plpython2u CASCADE; CREATE EXTENSION hstore_plpython3u CASCADE;
-- test hstore -> python -- test hstore -> python
CREATE FUNCTION test1(val hstore) RETURNS int CREATE FUNCTION test1(val hstore) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
assert isinstance(val, dict) assert isinstance(val, dict)
@ -16,7 +16,7 @@ SELECT test1('aa=>bb, cc=>NULL'::hstore);
-- the same with the versioned language name -- the same with the versioned language name
CREATE FUNCTION test1n(val hstore) RETURNS int CREATE FUNCTION test1n(val hstore) RETURNS int
LANGUAGE plpython2u LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
assert isinstance(val, dict) assert isinstance(val, dict)
@ -29,7 +29,7 @@ SELECT test1n('aa=>bb, cc=>NULL'::hstore);
-- test hstore[] -> python -- test hstore[] -> python
CREATE FUNCTION test1arr(val hstore[]) RETURNS int CREATE FUNCTION test1arr(val hstore[]) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
assert(val == [{'aa': 'bb', 'cc': None}, {'dd': 'ee'}]) assert(val == [{'aa': 'bb', 'cc': None}, {'dd': 'ee'}])
@ -41,7 +41,7 @@ SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']);
-- test python -> hstore -- test python -> hstore
CREATE FUNCTION test2(a int, b text) RETURNS hstore CREATE FUNCTION test2(a int, b text) RETURNS hstore
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
val = {'a': a, 'b': b, 'c': None} val = {'a': a, 'b': b, 'c': None}
@ -56,7 +56,7 @@ SELECT test2(1, 'boo');
-- test python -> hstore[] -- test python -> hstore[]
CREATE FUNCTION test2arr() RETURNS hstore[] CREATE FUNCTION test2arr() RETURNS hstore[]
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
val = [{'a': 1, 'b': 'boo', 'c': None}, {'d': 2}] val = [{'a': 1, 'b': 'boo', 'c': None}, {'d': 2}]
@ -70,7 +70,7 @@ SELECT test2arr();
CREATE DOMAIN hstore_foo AS hstore CHECK(VALUE ? 'foo'); CREATE DOMAIN hstore_foo AS hstore CHECK(VALUE ? 'foo');
CREATE FUNCTION test2dom(fn text) RETURNS hstore_foo CREATE FUNCTION test2dom(fn text) RETURNS hstore_foo
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
return {'a': 1, fn: 'boo', 'c': None} return {'a': 1, fn: 'boo', 'c': None}
@ -82,7 +82,7 @@ SELECT test2dom('bar'); -- fail
-- test as part of prepare/execute -- test as part of prepare/execute
CREATE FUNCTION test3() RETURNS void CREATE FUNCTION test3() RETURNS void
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
rv = plpy.execute("SELECT 'aa=>bb, cc=>NULL'::hstore AS col1") rv = plpy.execute("SELECT 'aa=>bb, cc=>NULL'::hstore AS col1")
@ -103,7 +103,7 @@ INSERT INTO test1 VALUES (1, 'aa=>bb, cc=>NULL');
SELECT * FROM test1; SELECT * FROM test1;
CREATE FUNCTION test4() RETURNS trigger CREATE FUNCTION test4() RETURNS trigger
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
assert(TD["new"] == {'a': 1, 'b': {'aa': 'bb', 'cc': None}}) assert(TD["new"] == {'a': 1, 'b': {'aa': 'bb', 'cc': None}})

View File

@ -1,6 +1,4 @@
# Generated subdirectories # Generated subdirectories
/expected/python3/
/log/ /log/
/results/ /results/
/sql/python3/
/tmp_check/ /tmp_check/

View File

@ -12,7 +12,6 @@ EXTENSION = jsonb_plpython3u
DATA = jsonb_plpython3u--1.0.sql DATA = jsonb_plpython3u--1.0.sql
REGRESS = jsonb_plpython REGRESS = jsonb_plpython
REGRESS_PLPYTHON3_MANGLE := $(REGRESS)
ifdef USE_PGXS ifdef USE_PGXS
PG_CONFIG = pg_config PG_CONFIG = pg_config
@ -33,9 +32,3 @@ else
rpathdir = $(python_libdir) rpathdir = $(python_libdir)
SHLIB_LINK += $(python_libspec) $(python_additional_libs) SHLIB_LINK += $(python_libspec) $(python_additional_libs)
endif endif
ifeq ($(python_majorversion),2)
REGRESS_OPTS += --load-extension=plpythonu --load-extension=jsonb_plpythonu
endif
include $(top_srcdir)/src/pl/plpython/regress-python3-mangle.mk

View File

@ -1,8 +1,8 @@
CREATE EXTENSION jsonb_plpython2u CASCADE; CREATE EXTENSION jsonb_plpython3u CASCADE;
NOTICE: installing required extension "plpython2u" NOTICE: installing required extension "plpython3u"
-- test jsonb -> python dict -- test jsonb -> python dict
CREATE FUNCTION test1(val jsonb) RETURNS int CREATE FUNCTION test1(val jsonb) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert isinstance(val, dict) assert isinstance(val, dict)
@ -18,7 +18,7 @@ SELECT test1('{"a": 1, "c": "NULL"}'::jsonb);
-- test jsonb -> python dict -- test jsonb -> python dict
-- complex dict with dicts as value -- complex dict with dicts as value
CREATE FUNCTION test1complex(val jsonb) RETURNS int CREATE FUNCTION test1complex(val jsonb) RETURNS int
LANGUAGE plpython2u LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert isinstance(val, dict) assert isinstance(val, dict)
@ -34,7 +34,7 @@ SELECT test1complex('{"d": {"d": 1}}'::jsonb);
-- test jsonb[] -> python dict -- test jsonb[] -> python dict
-- dict with array as value -- dict with array as value
CREATE FUNCTION test1arr(val jsonb) RETURNS int CREATE FUNCTION test1arr(val jsonb) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert isinstance(val, dict) assert isinstance(val, dict)
@ -50,7 +50,7 @@ SELECT test1arr('{"d":[12, 1]}'::jsonb);
-- test jsonb[] -> python list -- test jsonb[] -> python list
-- simple list -- simple list
CREATE FUNCTION test2arr(val jsonb) RETURNS int CREATE FUNCTION test2arr(val jsonb) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert isinstance(val, list) assert isinstance(val, list)
@ -66,7 +66,7 @@ SELECT test2arr('[12, 1]'::jsonb);
-- test jsonb[] -> python list -- test jsonb[] -> python list
-- array of dicts -- array of dicts
CREATE FUNCTION test3arr(val jsonb) RETURNS int CREATE FUNCTION test3arr(val jsonb) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert isinstance(val, list) assert isinstance(val, list)
@ -81,7 +81,7 @@ SELECT test3arr('[{"a": 1, "b": 2}, {"c": 3,"d": 4}]'::jsonb);
-- test jsonb int -> python int -- test jsonb int -> python int
CREATE FUNCTION test1int(val jsonb) RETURNS int CREATE FUNCTION test1int(val jsonb) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert(val == 1) assert(val == 1)
@ -95,7 +95,7 @@ SELECT test1int('1'::jsonb);
-- test jsonb string -> python string -- test jsonb string -> python string
CREATE FUNCTION test1string(val jsonb) RETURNS text CREATE FUNCTION test1string(val jsonb) RETURNS text
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert(val == "a") assert(val == "a")
@ -109,7 +109,7 @@ SELECT test1string('"a"'::jsonb);
-- test jsonb null -> python None -- test jsonb null -> python None
CREATE FUNCTION test1null(val jsonb) RETURNS int CREATE FUNCTION test1null(val jsonb) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert(val == None) assert(val == None)
@ -123,7 +123,7 @@ SELECT test1null('null'::jsonb);
-- test python -> jsonb -- test python -> jsonb
CREATE FUNCTION roundtrip(val jsonb) RETURNS jsonb CREATE FUNCTION roundtrip(val jsonb) RETURNS jsonb
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
as $$ as $$
return val return val
@ -238,7 +238,7 @@ SELECT roundtrip('["string", "string2"]'::jsonb);
-- complex numbers -> jsonb -- complex numbers -> jsonb
CREATE FUNCTION testComplexNumbers() RETURNS jsonb CREATE FUNCTION testComplexNumbers() RETURNS jsonb
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
x = 1 + 2j x = 1 + 2j
@ -250,7 +250,7 @@ CONTEXT: while creating return value
PL/Python function "testcomplexnumbers" PL/Python function "testcomplexnumbers"
-- range -> jsonb -- range -> jsonb
CREATE FUNCTION testRange() RETURNS jsonb CREATE FUNCTION testRange() RETURNS jsonb
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
x = range(3) x = range(3)
@ -264,7 +264,7 @@ SELECT testRange();
-- 0xff -> jsonb -- 0xff -> jsonb
CREATE FUNCTION testDecimal() RETURNS jsonb CREATE FUNCTION testDecimal() RETURNS jsonb
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
x = 0xff x = 0xff
@ -278,7 +278,7 @@ SELECT testDecimal();
-- tuple -> jsonb -- tuple -> jsonb
CREATE FUNCTION testTuple() RETURNS jsonb CREATE FUNCTION testTuple() RETURNS jsonb
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
x = (1, 'String', None) x = (1, 'String', None)
@ -292,7 +292,7 @@ SELECT testTuple();
-- interesting dict -> jsonb -- interesting dict -> jsonb
CREATE FUNCTION test_dict1() RETURNS jsonb CREATE FUNCTION test_dict1() RETURNS jsonb
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
x = {"a": 1, None: 2, 33: 3} x = {"a": 1, None: 2, 33: 3}

View File

@ -1,8 +1,8 @@
CREATE EXTENSION jsonb_plpython2u CASCADE; CREATE EXTENSION jsonb_plpython3u CASCADE;
-- test jsonb -> python dict -- test jsonb -> python dict
CREATE FUNCTION test1(val jsonb) RETURNS int CREATE FUNCTION test1(val jsonb) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert isinstance(val, dict) assert isinstance(val, dict)
@ -15,7 +15,7 @@ SELECT test1('{"a": 1, "c": "NULL"}'::jsonb);
-- test jsonb -> python dict -- test jsonb -> python dict
-- complex dict with dicts as value -- complex dict with dicts as value
CREATE FUNCTION test1complex(val jsonb) RETURNS int CREATE FUNCTION test1complex(val jsonb) RETURNS int
LANGUAGE plpython2u LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert isinstance(val, dict) assert isinstance(val, dict)
@ -29,7 +29,7 @@ SELECT test1complex('{"d": {"d": 1}}'::jsonb);
-- test jsonb[] -> python dict -- test jsonb[] -> python dict
-- dict with array as value -- dict with array as value
CREATE FUNCTION test1arr(val jsonb) RETURNS int CREATE FUNCTION test1arr(val jsonb) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert isinstance(val, dict) assert isinstance(val, dict)
@ -42,7 +42,7 @@ SELECT test1arr('{"d":[12, 1]}'::jsonb);
-- test jsonb[] -> python list -- test jsonb[] -> python list
-- simple list -- simple list
CREATE FUNCTION test2arr(val jsonb) RETURNS int CREATE FUNCTION test2arr(val jsonb) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert isinstance(val, list) assert isinstance(val, list)
@ -55,7 +55,7 @@ SELECT test2arr('[12, 1]'::jsonb);
-- test jsonb[] -> python list -- test jsonb[] -> python list
-- array of dicts -- array of dicts
CREATE FUNCTION test3arr(val jsonb) RETURNS int CREATE FUNCTION test3arr(val jsonb) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert isinstance(val, list) assert isinstance(val, list)
@ -67,7 +67,7 @@ SELECT test3arr('[{"a": 1, "b": 2}, {"c": 3,"d": 4}]'::jsonb);
-- test jsonb int -> python int -- test jsonb int -> python int
CREATE FUNCTION test1int(val jsonb) RETURNS int CREATE FUNCTION test1int(val jsonb) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert(val == 1) assert(val == 1)
@ -78,7 +78,7 @@ SELECT test1int('1'::jsonb);
-- test jsonb string -> python string -- test jsonb string -> python string
CREATE FUNCTION test1string(val jsonb) RETURNS text CREATE FUNCTION test1string(val jsonb) RETURNS text
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert(val == "a") assert(val == "a")
@ -89,7 +89,7 @@ SELECT test1string('"a"'::jsonb);
-- test jsonb null -> python None -- test jsonb null -> python None
CREATE FUNCTION test1null(val jsonb) RETURNS int CREATE FUNCTION test1null(val jsonb) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
assert(val == None) assert(val == None)
@ -100,7 +100,7 @@ SELECT test1null('null'::jsonb);
-- test python -> jsonb -- test python -> jsonb
CREATE FUNCTION roundtrip(val jsonb) RETURNS jsonb CREATE FUNCTION roundtrip(val jsonb) RETURNS jsonb
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
as $$ as $$
return val return val
@ -129,7 +129,7 @@ SELECT roundtrip('["string", "string2"]'::jsonb);
-- complex numbers -> jsonb -- complex numbers -> jsonb
CREATE FUNCTION testComplexNumbers() RETURNS jsonb CREATE FUNCTION testComplexNumbers() RETURNS jsonb
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
x = 1 + 2j x = 1 + 2j
@ -140,7 +140,7 @@ SELECT testComplexNumbers();
-- range -> jsonb -- range -> jsonb
CREATE FUNCTION testRange() RETURNS jsonb CREATE FUNCTION testRange() RETURNS jsonb
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
x = range(3) x = range(3)
@ -151,7 +151,7 @@ SELECT testRange();
-- 0xff -> jsonb -- 0xff -> jsonb
CREATE FUNCTION testDecimal() RETURNS jsonb CREATE FUNCTION testDecimal() RETURNS jsonb
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
x = 0xff x = 0xff
@ -162,7 +162,7 @@ SELECT testDecimal();
-- tuple -> jsonb -- tuple -> jsonb
CREATE FUNCTION testTuple() RETURNS jsonb CREATE FUNCTION testTuple() RETURNS jsonb
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
x = (1, 'String', None) x = (1, 'String', None)
@ -173,7 +173,7 @@ SELECT testTuple();
-- interesting dict -> jsonb -- interesting dict -> jsonb
CREATE FUNCTION test_dict1() RETURNS jsonb CREATE FUNCTION test_dict1() RETURNS jsonb
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE jsonb TRANSFORM FOR TYPE jsonb
AS $$ AS $$
x = {"a": 1, None: 2, 33: 3} x = {"a": 1, None: 2, 33: 3}

View File

@ -1,6 +1,4 @@
# Generated subdirectories # Generated subdirectories
/expected/python3/
/log/ /log/
/results/ /results/
/sql/python3/
/tmp_check/ /tmp_check/

View File

@ -10,7 +10,6 @@ EXTENSION = ltree_plpython3u
DATA = ltree_plpython3u--1.0.sql DATA = ltree_plpython3u--1.0.sql
REGRESS = ltree_plpython REGRESS = ltree_plpython
REGRESS_PLPYTHON3_MANGLE := $(REGRESS)
PG_CPPFLAGS = $(python_includespec) -DPLPYTHON_LIBNAME='"plpython$(python_majorversion)"' PG_CPPFLAGS = $(python_includespec) -DPLPYTHON_LIBNAME='"plpython$(python_majorversion)"'
@ -37,9 +36,4 @@ SHLIB_LINK += $(python_libspec) $(python_additional_libs)
endif endif
REGRESS_OPTS += --load-extension=ltree REGRESS_OPTS += --load-extension=ltree
ifeq ($(python_majorversion),2)
REGRESS_OPTS += --load-extension=plpythonu --load-extension=ltree_plpythonu
endif
EXTRA_INSTALL += contrib/ltree EXTRA_INSTALL += contrib/ltree
include $(top_srcdir)/src/pl/plpython/regress-python3-mangle.mk

View File

@ -1,7 +1,7 @@
CREATE EXTENSION ltree_plpython2u CASCADE; CREATE EXTENSION ltree_plpython3u CASCADE;
NOTICE: installing required extension "plpython2u" NOTICE: installing required extension "plpython3u"
CREATE FUNCTION test1(val ltree) RETURNS int CREATE FUNCTION test1(val ltree) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE ltree TRANSFORM FOR TYPE ltree
AS $$ AS $$
plpy.info(repr(val)) plpy.info(repr(val))
@ -15,7 +15,7 @@ INFO: ['aa', 'bb', 'cc']
(1 row) (1 row)
CREATE FUNCTION test1n(val ltree) RETURNS int CREATE FUNCTION test1n(val ltree) RETURNS int
LANGUAGE plpython2u LANGUAGE plpython3u
TRANSFORM FOR TYPE ltree TRANSFORM FOR TYPE ltree
AS $$ AS $$
plpy.info(repr(val)) plpy.info(repr(val))
@ -29,7 +29,7 @@ INFO: ['aa', 'bb', 'cc']
(1 row) (1 row)
CREATE FUNCTION test2() RETURNS ltree CREATE FUNCTION test2() RETURNS ltree
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE ltree TRANSFORM FOR TYPE ltree
AS $$ AS $$
return ['foo', 'bar', 'baz'] return ['foo', 'bar', 'baz']

View File

@ -1,8 +1,8 @@
CREATE EXTENSION ltree_plpython2u CASCADE; CREATE EXTENSION ltree_plpython3u CASCADE;
CREATE FUNCTION test1(val ltree) RETURNS int CREATE FUNCTION test1(val ltree) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE ltree TRANSFORM FOR TYPE ltree
AS $$ AS $$
plpy.info(repr(val)) plpy.info(repr(val))
@ -13,7 +13,7 @@ SELECT test1('aa.bb.cc'::ltree);
CREATE FUNCTION test1n(val ltree) RETURNS int CREATE FUNCTION test1n(val ltree) RETURNS int
LANGUAGE plpython2u LANGUAGE plpython3u
TRANSFORM FOR TYPE ltree TRANSFORM FOR TYPE ltree
AS $$ AS $$
plpy.info(repr(val)) plpy.info(repr(val))
@ -24,7 +24,7 @@ SELECT test1n('aa.bb.cc'::ltree);
CREATE FUNCTION test2() RETURNS ltree CREATE FUNCTION test2() RETURNS ltree
LANGUAGE plpythonu LANGUAGE plpython3u
TRANSFORM FOR TYPE ltree TRANSFORM FOR TYPE ltree
AS $$ AS $$
return ['foo', 'bar', 'baz'] return ['foo', 'bar', 'baz']

View File

@ -1,7 +1,5 @@
/spiexceptions.h /spiexceptions.h
# Generated subdirectories # Generated subdirectories
/expected/python3/
/log/ /log/
/results/ /results/
/sql/python3/
/tmp_check/ /tmp_check/

View File

@ -35,9 +35,6 @@ OBJS = \
plpy_util.o plpy_util.o
DATA = $(NAME)u.control $(NAME)u--1.0.sql DATA = $(NAME)u.control $(NAME)u--1.0.sql
ifeq ($(python_majorversion),2)
DATA += plpythonu.control plpythonu--1.0.sql
endif
# header files to install - it's not clear which of these might be needed # header files to install - it's not clear which of these might be needed
# so install them all. # so install them all.
@ -77,11 +74,6 @@ endif # win32
SHLIB_LINK = $(python_libspec) $(python_additional_libs) $(filter -lintl,$(LIBS)) SHLIB_LINK = $(python_libspec) $(python_additional_libs) $(filter -lintl,$(LIBS))
REGRESS_OPTS = --dbname=$(PL_TESTDB) REGRESS_OPTS = --dbname=$(PL_TESTDB)
# Only load plpythonu with Python 2. The test files themselves load
# the versioned language plpython(2|3)u.
ifeq ($(python_majorversion),2)
REGRESS_OPTS += --load-extension=plpythonu
endif
REGRESS = \ REGRESS = \
plpython_schema \ plpython_schema \
@ -108,8 +100,6 @@ REGRESS = \
plpython_transaction \ plpython_transaction \
plpython_drop plpython_drop
REGRESS_PLPYTHON3_MANGLE := $(REGRESS)
include $(top_srcdir)/src/Makefile.shlib include $(top_srcdir)/src/Makefile.shlib
all: all-lib all: all-lib
@ -127,7 +117,6 @@ uninstall: uninstall-lib uninstall-data
install-data: installdirs install-data: installdirs
$(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) '$(DESTDIR)$(datadir)/extension/' $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) '$(DESTDIR)$(datadir)/extension/'
$(INSTALL_DATA) $(addprefix $(srcdir)/, $(INCS)) '$(DESTDIR)$(includedir_server)' $(INSTALL_DATA) $(addprefix $(srcdir)/, $(INCS)) '$(DESTDIR)$(includedir_server)'
$(INSTALL_DATA) $(srcdir)/regress-python3-mangle.mk '$(DESTDIR)$(pgxsdir)/src/pl/plpython'
uninstall-data: uninstall-data:
rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(DATA))) rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(DATA)))
@ -136,9 +125,6 @@ uninstall-data:
.PHONY: install-data uninstall-data .PHONY: install-data uninstall-data
include $(srcdir)/regress-python3-mangle.mk
check: submake-pg-regress check: submake-pg-regress
$(pg_regress_check) $(REGRESS_OPTS) $(REGRESS) $(pg_regress_check) $(REGRESS_OPTS) $(REGRESS)

View File

@ -2,14 +2,14 @@
-- Tests for procedures / CALL syntax -- Tests for procedures / CALL syntax
-- --
CREATE PROCEDURE test_proc1() CREATE PROCEDURE test_proc1()
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
pass pass
$$; $$;
CALL test_proc1(); CALL test_proc1();
-- error: can't return non-None -- error: can't return non-None
CREATE PROCEDURE test_proc2() CREATE PROCEDURE test_proc2()
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
return 5 return 5
$$; $$;
@ -18,7 +18,7 @@ ERROR: PL/Python procedure did not return None
CONTEXT: PL/Python procedure "test_proc2" CONTEXT: PL/Python procedure "test_proc2"
CREATE TABLE test1 (a int); CREATE TABLE test1 (a int);
CREATE PROCEDURE test_proc3(x int) CREATE PROCEDURE test_proc3(x int)
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plpy.execute("INSERT INTO test1 VALUES (%s)" % x) plpy.execute("INSERT INTO test1 VALUES (%s)" % x)
$$; $$;
@ -31,7 +31,7 @@ SELECT * FROM test1;
-- output arguments -- output arguments
CREATE PROCEDURE test_proc5(INOUT a text) CREATE PROCEDURE test_proc5(INOUT a text)
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
return [a + '+' + a] return [a + '+' + a]
$$; $$;
@ -42,7 +42,7 @@ CALL test_proc5('abc');
(1 row) (1 row)
CREATE PROCEDURE test_proc6(a int, INOUT b int, INOUT c int) CREATE PROCEDURE test_proc6(a int, INOUT b int, INOUT c int)
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
return (b * a, c * a) return (b * a, c * a)
$$; $$;
@ -54,7 +54,7 @@ CALL test_proc6(2, 3, 4);
-- OUT parameters -- OUT parameters
CREATE PROCEDURE test_proc9(IN a int, OUT b int) CREATE PROCEDURE test_proc9(IN a int, OUT b int)
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plpy.notice("a: %s" % (a)) plpy.notice("a: %s" % (a))
return (a * 2,) return (a * 2,)

View File

@ -1,6 +1,6 @@
CREATE FUNCTION multiout_simple(OUT i integer, OUT j integer) AS $$ CREATE FUNCTION multiout_simple(OUT i integer, OUT j integer) AS $$
return (1, 2) return (1, 2)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT multiout_simple(); SELECT multiout_simple();
multiout_simple multiout_simple
----------------- -----------------
@ -27,7 +27,7 @@ SELECT (multiout_simple()).j + 3;
CREATE FUNCTION multiout_simple_setof(n integer = 1, OUT integer, OUT integer) RETURNS SETOF record AS $$ CREATE FUNCTION multiout_simple_setof(n integer = 1, OUT integer, OUT integer) RETURNS SETOF record AS $$
return [(1, 2)] * n return [(1, 2)] * n
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT multiout_simple_setof(); SELECT multiout_simple_setof();
multiout_simple_setof multiout_simple_setof
----------------------- -----------------------
@ -67,7 +67,7 @@ elif typ == 'obj':
return type_record return type_record
elif typ == 'str': elif typ == 'str':
return "('%s',%r)" % (first, second) return "('%s',%r)" % (first, second)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM multiout_record_as('dict', 'foo', 1, 'f'); SELECT * FROM multiout_record_as('dict', 'foo', 1, 'f');
first | second first | second
-------+-------- -------+--------
@ -237,7 +237,7 @@ for i in range(n):
power = 2 ** i power = 2 ** i
length = plpy.execute("select length('%d')" % power)[0]['length'] length = plpy.execute("select length('%d')" % power)[0]['length']
yield power, length yield power, length
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM multiout_setof(3); SELECT * FROM multiout_setof(3);
power_of_2 | length power_of_2 | length
------------+-------- ------------+--------
@ -260,7 +260,7 @@ CREATE FUNCTION multiout_return_table() RETURNS TABLE (x integer, y text) AS $$
return [{'x': 4, 'y' :'four'}, return [{'x': 4, 'y' :'four'},
{'x': 7, 'y' :'seven'}, {'x': 7, 'y' :'seven'},
{'x': 0, 'y' :'zero'}] {'x': 0, 'y' :'zero'}]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM multiout_return_table(); SELECT * FROM multiout_return_table();
x | y x | y
---+------- ---+-------
@ -273,7 +273,7 @@ CREATE FUNCTION multiout_array(OUT integer[], OUT text) RETURNS SETOF record AS
yield [[1], 'a'] yield [[1], 'a']
yield [[1,2], 'b'] yield [[1,2], 'b']
yield [[1,2,3], None] yield [[1,2,3], None]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM multiout_array(); SELECT * FROM multiout_array();
column1 | column2 column1 | column2
---------+--------- ---------+---------
@ -284,11 +284,11 @@ SELECT * FROM multiout_array();
CREATE FUNCTION singleout_composite(OUT type_record) AS $$ CREATE FUNCTION singleout_composite(OUT type_record) AS $$
return {'first': 1, 'second': 2} return {'first': 1, 'second': 2}
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION multiout_composite(OUT type_record) RETURNS SETOF type_record AS $$ CREATE FUNCTION multiout_composite(OUT type_record) RETURNS SETOF type_record AS $$
return [{'first': 1, 'second': 2}, return [{'first': 1, 'second': 2},
{'first': 3, 'second': 4 }] {'first': 3, 'second': 4 }]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM singleout_composite(); SELECT * FROM singleout_composite();
first | second first | second
-------+-------- -------+--------
@ -305,7 +305,7 @@ SELECT * FROM multiout_composite();
-- composite OUT parameters in functions returning RECORD not supported yet -- composite OUT parameters in functions returning RECORD not supported yet
CREATE FUNCTION multiout_composite(INOUT n integer, OUT type_record) AS $$ CREATE FUNCTION multiout_composite(INOUT n integer, OUT type_record) AS $$
return (n, (n * 2, n * 3)) return (n, (n * 2, n * 3))
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION multiout_table_type_setof(typ text, returnnull boolean, INOUT n integer, OUT table_record) RETURNS SETOF record AS $$ CREATE FUNCTION multiout_table_type_setof(typ text, returnnull boolean, INOUT n integer, OUT table_record) RETURNS SETOF record AS $$
if returnnull: if returnnull:
d = None d = None
@ -323,7 +323,7 @@ elif typ == 'str':
d = "(%r,%r)" % (n * 2, n * 3) d = "(%r,%r)" % (n * 2, n * 3)
for i in range(n): for i in range(n):
yield (i, d) yield (i, d)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM multiout_composite(2); SELECT * FROM multiout_composite(2);
n | column2 n | column2
---+--------- ---+---------
@ -438,7 +438,7 @@ CREATE TABLE changing (
CREATE FUNCTION changing_test(OUT n integer, OUT changing) RETURNS SETOF record AS $$ CREATE FUNCTION changing_test(OUT n integer, OUT changing) RETURNS SETOF record AS $$
return [(1, {'i': 1, 'j': 2}), return [(1, {'i': 1, 'j': 2}),
(1, (3, 4))] (1, (3, 4))]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM changing_test(); SELECT * FROM changing_test();
n | column2 n | column2
---+--------- ---+---------
@ -474,7 +474,7 @@ yield {'tab': [('first', 1), ('second', 2)],
yield {'tab': [('first', 1), ('second', 2)], yield {'tab': [('first', 1), ('second', 2)],
'typ': [{'first': 'third', 'second': 3}, 'typ': [{'first': 'third', 'second': 3},
{'first': 'fourth', 'second': 4}]} {'first': 'fourth', 'second': 4}]}
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM composite_types_table(); SELECT * FROM composite_types_table();
tab | typ tab | typ
----------------------------+---------------------------- ----------------------------+----------------------------
@ -486,7 +486,7 @@ SELECT * FROM composite_types_table();
-- check what happens if the output record descriptor changes -- check what happens if the output record descriptor changes
CREATE FUNCTION return_record(t text) RETURNS record AS $$ CREATE FUNCTION return_record(t text) RETURNS record AS $$
return {'t': t, 'val': 10} return {'t': t, 'val': 10}
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM return_record('abc') AS r(t text, val integer); SELECT * FROM return_record('abc') AS r(t text, val integer);
t | val t | val
-----+----- -----+-----
@ -525,7 +525,7 @@ SELECT * FROM return_record('999') AS r(val text, t integer);
CREATE FUNCTION return_record_2(t text) RETURNS record AS $$ CREATE FUNCTION return_record_2(t text) RETURNS record AS $$
return {'v1':1,'v2':2,t:3} return {'v1':1,'v2':2,t:3}
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM return_record_2('v3') AS (v3 int, v2 int, v1 int); SELECT * FROM return_record_2('v3') AS (v3 int, v2 int, v1 int);
v3 | v2 | v1 v3 | v2 | v1
----+----+---- ----+----+----
@ -572,7 +572,7 @@ SELECT * FROM return_record_2('v3') AS (v1 int, v2 int, v3 int);
-- multi-dimensional array of composite types. -- multi-dimensional array of composite types.
CREATE FUNCTION composite_type_as_list() RETURNS type_record[] AS $$ CREATE FUNCTION composite_type_as_list() RETURNS type_record[] AS $$
return [[('first', 1), ('second', 1)], [('first', 2), ('second', 2)], [('first', 3), ('second', 3)]]; return [[('first', 1), ('second', 1)], [('first', 2), ('second', 2)], [('first', 3), ('second', 3)]];
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM composite_type_as_list(); SELECT * FROM composite_type_as_list();
composite_type_as_list composite_type_as_list
------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------
@ -585,7 +585,7 @@ SELECT * FROM composite_type_as_list();
-- on the issue. -- on the issue.
CREATE FUNCTION composite_type_as_list_broken() RETURNS type_record[] AS $$ CREATE FUNCTION composite_type_as_list_broken() RETURNS type_record[] AS $$
return [['first', 1]]; return [['first', 1]];
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM composite_type_as_list_broken(); SELECT * FROM composite_type_as_list_broken();
ERROR: malformed record literal: "first" ERROR: malformed record literal: "first"
DETAIL: Missing left parenthesis. DETAIL: Missing left parenthesis.

View File

@ -1,8 +1,6 @@
DO $$ plpy.notice("This is plpythonu.") $$ LANGUAGE plpythonu; DO $$ plpy.notice("This is plpython3u.") $$ LANGUAGE plpython3u;
NOTICE: This is plpythonu. NOTICE: This is plpython3u.
DO $$ plpy.notice("This is plpython2u.") $$ LANGUAGE plpython2u; DO $$ raise Exception("error test") $$ LANGUAGE plpython3u;
NOTICE: This is plpython2u.
DO $$ raise Exception("error test") $$ LANGUAGE plpythonu;
ERROR: Exception: error test ERROR: Exception: error test
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
PL/Python anonymous code block, line 1, in <module> PL/Python anonymous code block, line 1, in <module>

View File

@ -2,5 +2,4 @@
-- For paranoia's sake, don't leave an untrusted language sitting around -- For paranoia's sake, don't leave an untrusted language sitting around
-- --
SET client_min_messages = WARNING; SET client_min_messages = WARNING;
DROP EXTENSION plpythonu CASCADE; DROP EXTENSION plpython3u CASCADE;
DROP EXTENSION IF EXISTS plpython2u CASCADE;

View File

@ -17,7 +17,7 @@ plpy.info('This is message text.',
plpy.notice('notice', detail='some detail') plpy.notice('notice', detail='some detail')
plpy.warning('warning', detail='some detail') plpy.warning('warning', detail='some detail')
plpy.error('stop on error', detail='some detail', hint='some hint') plpy.error('stop on error', detail='some detail', hint='some hint')
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT elog_test(); SELECT elog_test();
INFO: info INFO: info
DETAIL: some detail DETAIL: some detail
@ -38,42 +38,42 @@ CONTEXT: Traceback (most recent call last):
PL/Python function "elog_test", line 18, in <module> PL/Python function "elog_test", line 18, in <module>
plpy.error('stop on error', detail='some detail', hint='some hint') plpy.error('stop on error', detail='some detail', hint='some hint')
PL/Python function "elog_test" PL/Python function "elog_test"
DO $$ plpy.info('other types', detail=(10, 20)) $$ LANGUAGE plpythonu; DO $$ plpy.info('other types', detail=(10, 20)) $$ LANGUAGE plpython3u;
INFO: other types INFO: other types
DETAIL: (10, 20) DETAIL: (10, 20)
DO $$ DO $$
import time; import time;
from datetime import date from datetime import date
plpy.info('other types', detail=date(2016, 2, 26)) plpy.info('other types', detail=date(2016, 2, 26))
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
INFO: other types INFO: other types
DETAIL: 2016-02-26 DETAIL: 2016-02-26
DO $$ DO $$
basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
plpy.info('other types', detail=basket) plpy.info('other types', detail=basket)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
INFO: other types INFO: other types
DETAIL: ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] DETAIL: ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
-- should fail -- should fail
DO $$ plpy.info('wrong sqlstate', sqlstate='54444A') $$ LANGUAGE plpythonu; DO $$ plpy.info('wrong sqlstate', sqlstate='54444A') $$ LANGUAGE plpython3u;
ERROR: ValueError: invalid SQLSTATE code ERROR: ValueError: invalid SQLSTATE code
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
PL/Python anonymous code block, line 1, in <module> PL/Python anonymous code block, line 1, in <module>
plpy.info('wrong sqlstate', sqlstate='54444A') plpy.info('wrong sqlstate', sqlstate='54444A')
PL/Python anonymous code block PL/Python anonymous code block
DO $$ plpy.info('unsupported argument', blabla='fooboo') $$ LANGUAGE plpythonu; DO $$ plpy.info('unsupported argument', blabla='fooboo') $$ LANGUAGE plpython3u;
ERROR: TypeError: 'blabla' is an invalid keyword argument for this function ERROR: TypeError: 'blabla' is an invalid keyword argument for this function
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
PL/Python anonymous code block, line 1, in <module> PL/Python anonymous code block, line 1, in <module>
plpy.info('unsupported argument', blabla='fooboo') plpy.info('unsupported argument', blabla='fooboo')
PL/Python anonymous code block PL/Python anonymous code block
DO $$ plpy.info('first message', message='second message') $$ LANGUAGE plpythonu; DO $$ plpy.info('first message', message='second message') $$ LANGUAGE plpython3u;
ERROR: TypeError: argument 'message' given by name and position ERROR: TypeError: argument 'message' given by name and position
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
PL/Python anonymous code block, line 1, in <module> PL/Python anonymous code block, line 1, in <module>
plpy.info('first message', message='second message') plpy.info('first message', message='second message')
PL/Python anonymous code block PL/Python anonymous code block
DO $$ plpy.info('first message', 'second message', message='third message') $$ LANGUAGE plpythonu; DO $$ plpy.info('first message', 'second message', message='third message') $$ LANGUAGE plpython3u;
ERROR: TypeError: argument 'message' given by name and position ERROR: TypeError: argument 'message' given by name and position
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
PL/Python anonymous code block, line 1, in <module> PL/Python anonymous code block, line 1, in <module>
@ -96,7 +96,7 @@ kwargs = {
} }
# ignore None values # ignore None values
plpy.error(**dict((k, v) for k, v in iter(kwargs.items()) if v)) plpy.error(**dict((k, v) for k, v in iter(kwargs.items()) if v))
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT raise_exception('hello', 'world'); SELECT raise_exception('hello', 'world');
ERROR: plpy.Error: hello ERROR: plpy.Error: hello
DETAIL: world DETAIL: world
@ -180,26 +180,35 @@ END;
$$; $$;
NOTICE: handled exception NOTICE: handled exception
DETAIL: message:(plpy.Error: message text), detail:(detail text), hint: (hint text), sqlstate: (XX555), schema_name:(schema text), table_name:(table text), column_name:(column text), datatype_name:(datatype text), constraint_name:(constraint text) DETAIL: message:(plpy.Error: message text), detail:(detail text), hint: (hint text), sqlstate: (XX555), schema_name:(schema text), table_name:(table text), column_name:(column text), datatype_name:(datatype text), constraint_name:(constraint text)
-- The displayed context is different between Python2 and Python3,
-- but that's not important for this test.
\set SHOW_CONTEXT never
DO $$ DO $$
try: try:
plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table_name => 'users_tab', _datatype_name => 'user_type')") plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table_name => 'users_tab', _datatype_name => 'user_type')")
except Exception as e: except Exception as e:
plpy.info(e.spidata) plpy.info(e.spidata)
raise e raise e
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
INFO: (119577128, None, 'some hint', None, 0, None, 'users_tab', None, 'user_type', None) INFO: (119577128, None, 'some hint', None, 0, None, 'users_tab', None, 'user_type', None)
ERROR: plpy.SPIError: plpy.Error: my message ERROR: plpy.SPIError: plpy.Error: my message
HINT: some hint HINT: some hint
CONTEXT: Traceback (most recent call last):
PL/Python anonymous code block, line 6, in <module>
raise e
PL/Python anonymous code block, line 3, in __plpython_inline_block
plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table_name => 'users_tab', _datatype_name => 'user_type')")
PL/Python anonymous code block
DO $$ DO $$
try: try:
plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table_name = 'users_tab', datatype_name = 'user_type') plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table_name = 'users_tab', datatype_name = 'user_type')
except Exception as 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)) plpy.info('sqlstate: %s, hint: %s, table_name: %s, datatype_name: %s' % (e.sqlstate, e.hint, e.table_name, e.datatype_name))
raise e raise e
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
INFO: sqlstate: XX987, hint: some hint, table_name: users_tab, datatype_name: user_type INFO: sqlstate: XX987, hint: some hint, table_name: users_tab, datatype_name: user_type
ERROR: plpy.Error: my message ERROR: plpy.Error: my message
HINT: some hint HINT: some hint
CONTEXT: Traceback (most recent call last):
PL/Python anonymous code block, line 6, in <module>
raise e
PL/Python anonymous code block, line 3, in __plpython_inline_block
plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table_name = 'users_tab', datatype_name = 'user_type')
PL/Python anonymous code block

View File

@ -6,7 +6,7 @@
CREATE FUNCTION python_syntax_error() RETURNS text CREATE FUNCTION python_syntax_error() RETURNS text
AS AS
'.syntaxerror' '.syntaxerror'
LANGUAGE plpythonu; LANGUAGE plpython3u;
ERROR: could not compile PL/Python function "python_syntax_error" ERROR: could not compile PL/Python function "python_syntax_error"
DETAIL: SyntaxError: invalid syntax (<string>, line 2) DETAIL: SyntaxError: invalid syntax (<string>, line 2)
/* With check_function_bodies = false the function should get defined /* With check_function_bodies = false the function should get defined
@ -16,7 +16,7 @@ SET check_function_bodies = false;
CREATE FUNCTION python_syntax_error() RETURNS text CREATE FUNCTION python_syntax_error() RETURNS text
AS AS
'.syntaxerror' '.syntaxerror'
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT python_syntax_error(); SELECT python_syntax_error();
ERROR: could not compile PL/Python function "python_syntax_error" ERROR: could not compile PL/Python function "python_syntax_error"
DETAIL: SyntaxError: invalid syntax (<string>, line 2) DETAIL: SyntaxError: invalid syntax (<string>, line 2)
@ -30,7 +30,7 @@ RESET check_function_bodies;
CREATE FUNCTION sql_syntax_error() RETURNS text CREATE FUNCTION sql_syntax_error() RETURNS text
AS AS
'plpy.execute("syntax error")' 'plpy.execute("syntax error")'
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT sql_syntax_error(); SELECT sql_syntax_error();
ERROR: spiexceptions.SyntaxError: syntax error at or near "syntax" ERROR: spiexceptions.SyntaxError: syntax error at or near "syntax"
LINE 1: syntax error LINE 1: syntax error
@ -45,7 +45,7 @@ PL/Python function "sql_syntax_error"
CREATE FUNCTION exception_index_invalid(text) RETURNS text CREATE FUNCTION exception_index_invalid(text) RETURNS text
AS AS
'return args[1]' 'return args[1]'
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT exception_index_invalid('test'); SELECT exception_index_invalid('test');
ERROR: IndexError: list index out of range ERROR: IndexError: list index out of range
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
@ -58,7 +58,7 @@ CREATE FUNCTION exception_index_invalid_nested() RETURNS text
AS AS
'rv = plpy.execute("SELECT test5(''foo'')") 'rv = plpy.execute("SELECT test5(''foo'')")
return rv[0]' return rv[0]'
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT exception_index_invalid_nested(); SELECT exception_index_invalid_nested();
ERROR: spiexceptions.UndefinedFunction: function test5(unknown) does not exist ERROR: spiexceptions.UndefinedFunction: function test5(unknown) does not exist
LINE 1: SELECT test5('foo') LINE 1: SELECT test5('foo')
@ -81,7 +81,7 @@ if len(rv):
return rv[0]["fname"] return rv[0]["fname"]
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT invalid_type_uncaught('rick'); SELECT invalid_type_uncaught('rick');
ERROR: spiexceptions.UndefinedObject: type "test" does not exist ERROR: spiexceptions.UndefinedObject: type "test" does not exist
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
@ -105,7 +105,7 @@ if len(rv):
return rv[0]["fname"] return rv[0]["fname"]
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT invalid_type_caught('rick'); SELECT invalid_type_caught('rick');
NOTICE: type "test" does not exist NOTICE: type "test" does not exist
invalid_type_caught invalid_type_caught
@ -129,7 +129,7 @@ if len(rv):
return rv[0]["fname"] return rv[0]["fname"]
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT invalid_type_reraised('rick'); SELECT invalid_type_reraised('rick');
ERROR: plpy.Error: type "test" does not exist ERROR: plpy.Error: type "test" does not exist
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
@ -147,7 +147,7 @@ if len(rv):
return rv[0]["fname"] return rv[0]["fname"]
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT valid_type('rick'); SELECT valid_type('rick');
valid_type valid_type
------------ ------------
@ -170,7 +170,7 @@ def fun3():
fun3() fun3()
return "not reached" return "not reached"
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT nested_error(); SELECT nested_error();
ERROR: plpy.Error: boom ERROR: plpy.Error: boom
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
@ -199,7 +199,7 @@ def fun3():
fun3() fun3()
return "not reached" return "not reached"
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT nested_error_raise(); SELECT nested_error_raise();
ERROR: plpy.Error: boom ERROR: plpy.Error: boom
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
@ -228,7 +228,7 @@ def fun3():
fun3() fun3()
return "you''ve been warned" return "you''ve been warned"
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT nested_warning(); SELECT nested_warning();
WARNING: boom WARNING: boom
nested_warning nested_warning
@ -241,9 +241,9 @@ WARNING: boom
CREATE FUNCTION toplevel_attribute_error() RETURNS void AS CREATE FUNCTION toplevel_attribute_error() RETURNS void AS
$$ $$
plpy.nonexistent plpy.nonexistent
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT toplevel_attribute_error(); SELECT toplevel_attribute_error();
ERROR: AttributeError: 'module' object has no attribute 'nonexistent' ERROR: AttributeError: module 'plpy' has no attribute 'nonexistent'
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
PL/Python function "toplevel_attribute_error", line 2, in <module> PL/Python function "toplevel_attribute_error", line 2, in <module>
plpy.nonexistent plpy.nonexistent
@ -261,7 +261,7 @@ def third():
plpy.execute("select sql_error()") plpy.execute("select sql_error()")
first() first()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION sql_error() RETURNS void AS $$ CREATE OR REPLACE FUNCTION sql_error() RETURNS void AS $$
begin begin
select 1/0; select 1/0;
@ -274,7 +274,7 @@ end
$$ LANGUAGE plpgsql; $$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION sql_from_python_error() RETURNS void AS $$ CREATE OR REPLACE FUNCTION sql_from_python_error() RETURNS void AS $$
plpy.execute("select sql_error()") plpy.execute("select sql_error()")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT python_traceback(); SELECT python_traceback();
ERROR: spiexceptions.DivisionByZero: division by zero ERROR: spiexceptions.DivisionByZero: division by zero
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
@ -325,7 +325,7 @@ except spiexceptions.NotNullViolation as e:
plpy.notice("Violated the NOT NULL constraint, sqlstate %s" % e.sqlstate) plpy.notice("Violated the NOT NULL constraint, sqlstate %s" % e.sqlstate)
except spiexceptions.UniqueViolation as e: except spiexceptions.UniqueViolation as e:
plpy.notice("Violated the UNIQUE constraint, sqlstate %s" % e.sqlstate) plpy.notice("Violated the UNIQUE constraint, sqlstate %s" % e.sqlstate)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT specific_exception(2); SELECT specific_exception(2);
specific_exception specific_exception
-------------------- --------------------
@ -351,7 +351,7 @@ NOTICE: Violated the UNIQUE constraint, sqlstate 23505
CREATE FUNCTION python_unique_violation() RETURNS void AS $$ CREATE FUNCTION python_unique_violation() RETURNS void AS $$
plpy.execute("insert into specific values (1)") plpy.execute("insert into specific values (1)")
plpy.execute("insert into specific values (1)") plpy.execute("insert into specific values (1)")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION catch_python_unique_violation() RETURNS text AS $$ CREATE FUNCTION catch_python_unique_violation() RETURNS text AS $$
begin begin
begin begin
@ -374,7 +374,7 @@ CREATE FUNCTION manual_subxact() RETURNS void AS $$
plpy.execute("savepoint save") plpy.execute("savepoint save")
plpy.execute("create table foo(x integer)") plpy.execute("create table foo(x integer)")
plpy.execute("rollback to save") plpy.execute("rollback to save")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT manual_subxact(); SELECT manual_subxact();
ERROR: plpy.SPIError: SPI_execute failed: SPI_ERROR_TRANSACTION ERROR: plpy.SPIError: SPI_execute failed: SPI_ERROR_TRANSACTION
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
@ -389,7 +389,7 @@ rollback = plpy.prepare("rollback to save")
plpy.execute(save) plpy.execute(save)
plpy.execute("create table foo(x integer)") plpy.execute("create table foo(x integer)")
plpy.execute(rollback) plpy.execute(rollback)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT manual_subxact_prepared(); SELECT manual_subxact_prepared();
ERROR: plpy.SPIError: SPI_execute_plan failed: SPI_ERROR_TRANSACTION ERROR: plpy.SPIError: SPI_execute_plan failed: SPI_ERROR_TRANSACTION
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
@ -400,7 +400,7 @@ PL/Python function "manual_subxact_prepared"
*/ */
CREATE FUNCTION plpy_raise_spiexception() RETURNS void AS $$ CREATE FUNCTION plpy_raise_spiexception() RETURNS void AS $$
raise plpy.spiexceptions.DivisionByZero() raise plpy.spiexceptions.DivisionByZero()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
DO $$ DO $$
BEGIN BEGIN
SELECT plpy_raise_spiexception(); SELECT plpy_raise_spiexception();
@ -414,7 +414,7 @@ CREATE FUNCTION plpy_raise_spiexception_override() RETURNS void AS $$
exc = plpy.spiexceptions.DivisionByZero() exc = plpy.spiexceptions.DivisionByZero()
exc.sqlstate = 'SILLY' exc.sqlstate = 'SILLY'
raise exc raise exc
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
DO $$ DO $$
BEGIN BEGIN
SELECT plpy_raise_spiexception_override(); SELECT plpy_raise_spiexception_override();
@ -425,18 +425,18 @@ $$ LANGUAGE plpgsql;
/* test the context stack trace for nested execution levels /* test the context stack trace for nested execution levels
*/ */
CREATE FUNCTION notice_innerfunc() RETURNS int AS $$ CREATE FUNCTION notice_innerfunc() RETURNS int AS $$
plpy.execute("DO LANGUAGE plpythonu $x$ plpy.notice('inside DO') $x$") plpy.execute("DO LANGUAGE plpython3u $x$ plpy.notice('inside DO') $x$")
return 1 return 1
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION notice_outerfunc() RETURNS int AS $$ CREATE FUNCTION notice_outerfunc() RETURNS int AS $$
plpy.execute("SELECT notice_innerfunc()") plpy.execute("SELECT notice_innerfunc()")
return 1 return 1
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
\set SHOW_CONTEXT always \set SHOW_CONTEXT always
SELECT notice_outerfunc(); SELECT notice_outerfunc();
NOTICE: inside DO NOTICE: inside DO
CONTEXT: PL/Python anonymous code block CONTEXT: PL/Python anonymous code block
SQL statement "DO LANGUAGE plpythonu $x$ plpy.notice('inside DO') $x$" SQL statement "DO LANGUAGE plpython3u $x$ plpy.notice('inside DO') $x$"
PL/Python function "notice_innerfunc" PL/Python function "notice_innerfunc"
SQL statement "SELECT notice_innerfunc()" SQL statement "SELECT notice_innerfunc()"
PL/Python function "notice_outerfunc" PL/Python function "notice_outerfunc"

View File

@ -1,447 +0,0 @@
-- test error handling, i forgot to restore Warn_restart in
-- the trigger handler once. the errors and subsequent core dump were
-- interesting.
/* Flat out Python syntax error
*/
CREATE FUNCTION python_syntax_error() RETURNS text
AS
'.syntaxerror'
LANGUAGE plpython3u;
ERROR: could not compile PL/Python function "python_syntax_error"
DETAIL: SyntaxError: invalid syntax (<string>, line 2)
/* With check_function_bodies = false the function should get defined
* and the error reported when called
*/
SET check_function_bodies = false;
CREATE FUNCTION python_syntax_error() RETURNS text
AS
'.syntaxerror'
LANGUAGE plpython3u;
SELECT python_syntax_error();
ERROR: could not compile PL/Python function "python_syntax_error"
DETAIL: SyntaxError: invalid syntax (<string>, line 2)
/* Run the function twice to check if the hashtable entry gets cleaned up */
SELECT python_syntax_error();
ERROR: could not compile PL/Python function "python_syntax_error"
DETAIL: SyntaxError: invalid syntax (<string>, line 2)
RESET check_function_bodies;
/* Flat out syntax error
*/
CREATE FUNCTION sql_syntax_error() RETURNS text
AS
'plpy.execute("syntax error")'
LANGUAGE plpython3u;
SELECT sql_syntax_error();
ERROR: spiexceptions.SyntaxError: syntax error at or near "syntax"
LINE 1: syntax error
^
QUERY: syntax error
CONTEXT: Traceback (most recent call last):
PL/Python function "sql_syntax_error", line 1, in <module>
plpy.execute("syntax error")
PL/Python function "sql_syntax_error"
/* check the handling of uncaught python exceptions
*/
CREATE FUNCTION exception_index_invalid(text) RETURNS text
AS
'return args[1]'
LANGUAGE plpython3u;
SELECT exception_index_invalid('test');
ERROR: IndexError: list index out of range
CONTEXT: Traceback (most recent call last):
PL/Python function "exception_index_invalid", line 1, in <module>
return args[1]
PL/Python function "exception_index_invalid"
/* check handling of nested exceptions
*/
CREATE FUNCTION exception_index_invalid_nested() RETURNS text
AS
'rv = plpy.execute("SELECT test5(''foo'')")
return rv[0]'
LANGUAGE plpython3u;
SELECT exception_index_invalid_nested();
ERROR: spiexceptions.UndefinedFunction: function test5(unknown) does not exist
LINE 1: SELECT test5('foo')
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: SELECT test5('foo')
CONTEXT: Traceback (most recent call last):
PL/Python function "exception_index_invalid_nested", line 1, in <module>
rv = plpy.execute("SELECT test5('foo')")
PL/Python function "exception_index_invalid_nested"
/* a typo
*/
CREATE FUNCTION invalid_type_uncaught(a text) RETURNS text
AS
'if "plan" not in SD:
q = "SELECT fname FROM users WHERE lname = $1"
SD["plan"] = plpy.prepare(q, [ "test" ])
rv = plpy.execute(SD["plan"], [ a ])
if len(rv):
return rv[0]["fname"]
return None
'
LANGUAGE plpython3u;
SELECT invalid_type_uncaught('rick');
ERROR: spiexceptions.UndefinedObject: type "test" does not exist
CONTEXT: Traceback (most recent call last):
PL/Python function "invalid_type_uncaught", line 3, in <module>
SD["plan"] = plpy.prepare(q, [ "test" ])
PL/Python function "invalid_type_uncaught"
/* for what it's worth catch the exception generated by
* the typo, and return None
*/
CREATE FUNCTION invalid_type_caught(a text) RETURNS text
AS
'if "plan" not in SD:
q = "SELECT fname FROM users WHERE lname = $1"
try:
SD["plan"] = plpy.prepare(q, [ "test" ])
except plpy.SPIError as ex:
plpy.notice(str(ex))
return None
rv = plpy.execute(SD["plan"], [ a ])
if len(rv):
return rv[0]["fname"]
return None
'
LANGUAGE plpython3u;
SELECT invalid_type_caught('rick');
NOTICE: type "test" does not exist
invalid_type_caught
---------------------
(1 row)
/* for what it's worth catch the exception generated by
* the typo, and reraise it as a plain error
*/
CREATE FUNCTION invalid_type_reraised(a text) RETURNS text
AS
'if "plan" not in SD:
q = "SELECT fname FROM users WHERE lname = $1"
try:
SD["plan"] = plpy.prepare(q, [ "test" ])
except plpy.SPIError as ex:
plpy.error(str(ex))
rv = plpy.execute(SD["plan"], [ a ])
if len(rv):
return rv[0]["fname"]
return None
'
LANGUAGE plpython3u;
SELECT invalid_type_reraised('rick');
ERROR: plpy.Error: type "test" does not exist
CONTEXT: Traceback (most recent call last):
PL/Python function "invalid_type_reraised", line 6, in <module>
plpy.error(str(ex))
PL/Python function "invalid_type_reraised"
/* no typo no messing about
*/
CREATE FUNCTION valid_type(a text) RETURNS text
AS
'if "plan" not in SD:
SD["plan"] = plpy.prepare("SELECT fname FROM users WHERE lname = $1", [ "text" ])
rv = plpy.execute(SD["plan"], [ a ])
if len(rv):
return rv[0]["fname"]
return None
'
LANGUAGE plpython3u;
SELECT valid_type('rick');
valid_type
------------
(1 row)
/* error in nested functions to get a traceback
*/
CREATE FUNCTION nested_error() RETURNS text
AS
'def fun1():
plpy.error("boom")
def fun2():
fun1()
def fun3():
fun2()
fun3()
return "not reached"
'
LANGUAGE plpython3u;
SELECT nested_error();
ERROR: plpy.Error: boom
CONTEXT: Traceback (most recent call last):
PL/Python function "nested_error", line 10, in <module>
fun3()
PL/Python function "nested_error", line 8, in fun3
fun2()
PL/Python function "nested_error", line 5, in fun2
fun1()
PL/Python function "nested_error", line 2, in fun1
plpy.error("boom")
PL/Python function "nested_error"
/* raising plpy.Error is just like calling plpy.error
*/
CREATE FUNCTION nested_error_raise() RETURNS text
AS
'def fun1():
raise plpy.Error("boom")
def fun2():
fun1()
def fun3():
fun2()
fun3()
return "not reached"
'
LANGUAGE plpython3u;
SELECT nested_error_raise();
ERROR: plpy.Error: boom
CONTEXT: Traceback (most recent call last):
PL/Python function "nested_error_raise", line 10, in <module>
fun3()
PL/Python function "nested_error_raise", line 8, in fun3
fun2()
PL/Python function "nested_error_raise", line 5, in fun2
fun1()
PL/Python function "nested_error_raise", line 2, in fun1
raise plpy.Error("boom")
PL/Python function "nested_error_raise"
/* using plpy.warning should not produce a traceback
*/
CREATE FUNCTION nested_warning() RETURNS text
AS
'def fun1():
plpy.warning("boom")
def fun2():
fun1()
def fun3():
fun2()
fun3()
return "you''ve been warned"
'
LANGUAGE plpython3u;
SELECT nested_warning();
WARNING: boom
nested_warning
--------------------
you've been warned
(1 row)
/* AttributeError at toplevel used to give segfaults with the traceback
*/
CREATE FUNCTION toplevel_attribute_error() RETURNS void AS
$$
plpy.nonexistent
$$ LANGUAGE plpython3u;
SELECT toplevel_attribute_error();
ERROR: AttributeError: module 'plpy' has no attribute 'nonexistent'
CONTEXT: Traceback (most recent call last):
PL/Python function "toplevel_attribute_error", line 2, in <module>
plpy.nonexistent
PL/Python function "toplevel_attribute_error"
/* Calling PL/Python functions from SQL and vice versa should not lose context.
*/
CREATE OR REPLACE FUNCTION python_traceback() RETURNS void AS $$
def first():
second()
def second():
third()
def third():
plpy.execute("select sql_error()")
first()
$$ LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION sql_error() RETURNS void AS $$
begin
select 1/0;
end
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION python_from_sql_error() RETURNS void AS $$
begin
select python_traceback();
end
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION sql_from_python_error() RETURNS void AS $$
plpy.execute("select sql_error()")
$$ LANGUAGE plpython3u;
SELECT python_traceback();
ERROR: spiexceptions.DivisionByZero: division by zero
CONTEXT: Traceback (most recent call last):
PL/Python function "python_traceback", line 11, in <module>
first()
PL/Python function "python_traceback", line 3, in first
second()
PL/Python function "python_traceback", line 6, in second
third()
PL/Python function "python_traceback", line 9, in third
plpy.execute("select sql_error()")
PL/Python function "python_traceback"
SELECT sql_error();
ERROR: division by zero
CONTEXT: SQL statement "select 1/0"
PL/pgSQL function sql_error() line 3 at SQL statement
SELECT python_from_sql_error();
ERROR: spiexceptions.DivisionByZero: division by zero
CONTEXT: Traceback (most recent call last):
PL/Python function "python_traceback", line 11, in <module>
first()
PL/Python function "python_traceback", line 3, in first
second()
PL/Python function "python_traceback", line 6, in second
third()
PL/Python function "python_traceback", line 9, in third
plpy.execute("select sql_error()")
PL/Python function "python_traceback"
SQL statement "select python_traceback()"
PL/pgSQL function python_from_sql_error() line 3 at SQL statement
SELECT sql_from_python_error();
ERROR: spiexceptions.DivisionByZero: division by zero
CONTEXT: Traceback (most recent call last):
PL/Python function "sql_from_python_error", line 2, in <module>
plpy.execute("select sql_error()")
PL/Python function "sql_from_python_error"
/* check catching specific types of exceptions
*/
CREATE TABLE specific (
i integer PRIMARY KEY
);
CREATE FUNCTION specific_exception(i integer) RETURNS void AS
$$
from plpy import spiexceptions
try:
plpy.execute("insert into specific values (%s)" % (i or "NULL"));
except spiexceptions.NotNullViolation as e:
plpy.notice("Violated the NOT NULL constraint, sqlstate %s" % e.sqlstate)
except spiexceptions.UniqueViolation as e:
plpy.notice("Violated the UNIQUE constraint, sqlstate %s" % e.sqlstate)
$$ LANGUAGE plpython3u;
SELECT specific_exception(2);
specific_exception
--------------------
(1 row)
SELECT specific_exception(NULL);
NOTICE: Violated the NOT NULL constraint, sqlstate 23502
specific_exception
--------------------
(1 row)
SELECT specific_exception(2);
NOTICE: Violated the UNIQUE constraint, sqlstate 23505
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 plpython3u;
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 $$
plpy.execute("savepoint save")
plpy.execute("create table foo(x integer)")
plpy.execute("rollback to save")
$$ LANGUAGE plpython3u;
SELECT manual_subxact();
ERROR: plpy.SPIError: SPI_execute failed: SPI_ERROR_TRANSACTION
CONTEXT: Traceback (most recent call last):
PL/Python function "manual_subxact", line 2, in <module>
plpy.execute("savepoint save")
PL/Python function "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 plpython3u;
SELECT manual_subxact_prepared();
ERROR: plpy.SPIError: SPI_execute_plan failed: SPI_ERROR_TRANSACTION
CONTEXT: Traceback (most recent call last):
PL/Python function "manual_subxact_prepared", line 4, in <module>
plpy.execute(save)
PL/Python function "manual_subxact_prepared"
/* raising plpy.spiexception.* from python code should preserve sqlstate
*/
CREATE FUNCTION plpy_raise_spiexception() RETURNS void AS $$
raise plpy.spiexceptions.DivisionByZero()
$$ LANGUAGE plpython3u;
DO $$
BEGIN
SELECT plpy_raise_spiexception();
EXCEPTION WHEN division_by_zero THEN
-- NOOP
END
$$ LANGUAGE plpgsql;
/* setting a custom sqlstate should be handled
*/
CREATE FUNCTION plpy_raise_spiexception_override() RETURNS void AS $$
exc = plpy.spiexceptions.DivisionByZero()
exc.sqlstate = 'SILLY'
raise exc
$$ LANGUAGE plpython3u;
DO $$
BEGIN
SELECT plpy_raise_spiexception_override();
EXCEPTION WHEN SQLSTATE 'SILLY' THEN
-- NOOP
END
$$ LANGUAGE plpgsql;
/* test the context stack trace for nested execution levels
*/
CREATE FUNCTION notice_innerfunc() RETURNS int AS $$
plpy.execute("DO LANGUAGE plpythonu $x$ plpy.notice('inside DO') $x$")
return 1
$$ LANGUAGE plpythonu;
CREATE FUNCTION notice_outerfunc() RETURNS int AS $$
plpy.execute("SELECT notice_innerfunc()")
return 1
$$ LANGUAGE plpythonu;
\set SHOW_CONTEXT always
SELECT notice_outerfunc();
NOTICE: inside DO
CONTEXT: PL/Python anonymous code block
SQL statement "DO LANGUAGE plpythonu $x$ plpy.notice('inside DO') $x$"
PL/Python function "notice_innerfunc"
SQL statement "SELECT notice_innerfunc()"
PL/Python function "notice_outerfunc"
notice_outerfunc
------------------
1
(1 row)

View File

@ -8,7 +8,7 @@ CREATE FUNCTION global_test_one() returns text
if "global_test" not in GD: if "global_test" not in GD:
GD["global_test"] = "set by global_test_one" GD["global_test"] = "set by global_test_one"
return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]' return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION global_test_two() returns text CREATE FUNCTION global_test_two() returns text
AS AS
'if "global_test" not in SD: 'if "global_test" not in SD:
@ -16,7 +16,7 @@ CREATE FUNCTION global_test_two() returns text
if "global_test" not in GD: if "global_test" not in GD:
GD["global_test"] = "set by global_test_two" GD["global_test"] = "set by global_test_two"
return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]' return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION static_test() returns int4 CREATE FUNCTION static_test() returns int4
AS AS
'if "call" in SD: 'if "call" in SD:
@ -25,7 +25,7 @@ else:
SD["call"] = 1 SD["call"] = 1
return SD["call"] return SD["call"]
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT static_test(); SELECT static_test();
static_test static_test
------------- -------------

View File

@ -6,7 +6,7 @@ CREATE FUNCTION import_fail() returns text
except ImportError: except ImportError:
return "failed as expected" return "failed as expected"
return "succeeded, that wasn''t supposed to happen"' return "succeeded, that wasn''t supposed to happen"'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION import_succeed() returns text CREATE FUNCTION import_succeed() returns text
AS AS
'try: 'try:
@ -25,7 +25,7 @@ except Exception as ex:
plpy.notice("import failed -- %s" % str(ex)) plpy.notice("import failed -- %s" % str(ex))
return "failed, that wasn''t supposed to happen" return "failed, that wasn''t supposed to happen"
return "succeeded, as expected"' return "succeeded, as expected"'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION import_test_one(p text) RETURNS text CREATE FUNCTION import_test_one(p text) RETURNS text
AS AS
'try: 'try:
@ -35,7 +35,7 @@ except ImportError:
import sha import sha
digest = sha.new(p) digest = sha.new(p)
return digest.hexdigest()' return digest.hexdigest()'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION import_test_two(u users) RETURNS text CREATE FUNCTION import_test_two(u users) RETURNS text
AS AS
'plain = u["fname"] + u["lname"] 'plain = u["fname"] + u["lname"]
@ -46,7 +46,7 @@ except ImportError:
import sha import sha
digest = sha.new(plain); digest = sha.new(plain);
return "sha hash of " + plain + " is " + digest.hexdigest()' return "sha hash of " + plain + " is " + digest.hexdigest()'
LANGUAGE plpythonu; LANGUAGE plpython3u;
-- import python modules -- import python modules
-- --
SELECT import_fail(); SELECT import_fail();

View File

@ -3,13 +3,13 @@
-- --
CREATE OR REPLACE FUNCTION newline_lf() RETURNS integer AS CREATE OR REPLACE FUNCTION newline_lf() RETURNS integer AS
E'x = 100\ny = 23\nreturn x + y\n' E'x = 100\ny = 23\nreturn x + y\n'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION newline_cr() RETURNS integer AS CREATE OR REPLACE FUNCTION newline_cr() RETURNS integer AS
E'x = 100\ry = 23\rreturn x + y\r' E'x = 100\ry = 23\rreturn x + y\r'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION newline_crlf() RETURNS integer AS CREATE OR REPLACE FUNCTION newline_crlf() RETURNS integer AS
E'x = 100\r\ny = 23\r\nreturn x + y\r\n' E'x = 100\r\ny = 23\r\nreturn x + y\r\n'
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT newline_lf(); SELECT newline_lf();
newline_lf newline_lf
------------ ------------

View File

@ -3,12 +3,12 @@
-- --
CREATE FUNCTION test_param_names0(integer, integer) RETURNS int AS $$ CREATE FUNCTION test_param_names0(integer, integer) RETURNS int AS $$
return args[0] + args[1] return args[0] + args[1]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_param_names1(a0 integer, a1 text) RETURNS boolean AS $$ CREATE FUNCTION test_param_names1(a0 integer, a1 text) RETURNS boolean AS $$
assert a0 == args[0] assert a0 == args[0]
assert a1 == args[1] assert a1 == args[1]
return True return True
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_param_names2(u users) RETURNS text AS $$ CREATE FUNCTION test_param_names2(u users) RETURNS text AS $$
assert u == args[0] assert u == args[0]
if isinstance(u, dict): if isinstance(u, dict):
@ -19,7 +19,7 @@ if isinstance(u, dict):
else: else:
s = str(u) s = str(u)
return s return s
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
-- use deliberately wrong parameter names -- use deliberately wrong parameter names
CREATE FUNCTION test_param_names3(a0 integer) RETURNS boolean AS $$ CREATE FUNCTION test_param_names3(a0 integer) RETURNS boolean AS $$
try: try:
@ -28,7 +28,7 @@ try:
except NameError as e: except NameError as e:
assert e.args[0].find("a1") > -1 assert e.args[0].find("a1") > -1
return True return True
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT test_param_names0(2,7); SELECT test_param_names0(2,7);
test_param_names0 test_param_names0
------------------- -------------------

View File

@ -8,7 +8,7 @@ CREATE FUNCTION quote(t text, how text) RETURNS text AS $$
return plpy.quote_ident(t) return plpy.quote_ident(t)
else: else:
raise plpy.Error("unrecognized quote type %s" % how) raise plpy.Error("unrecognized quote type %s" % how)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT quote(t, 'literal') FROM (VALUES SELECT quote(t, 'literal') FROM (VALUES
('abc'), ('abc'),
('a''bc'), ('a''bc'),

View File

@ -23,7 +23,7 @@ elif typ == 'obj':
type_record.first = first type_record.first = first
type_record.second = second type_record.second = second
return type_record return type_record
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_type_record_as(typ text, first text, second integer, retnull boolean) RETURNS type_record AS $$ CREATE FUNCTION test_type_record_as(typ text, first text, second integer, retnull boolean) RETURNS type_record AS $$
if retnull: if retnull:
return None return None
@ -40,17 +40,17 @@ elif typ == 'obj':
return type_record return type_record
elif typ == 'str': elif typ == 'str':
return "('%s',%r)" % (first, second) return "('%s',%r)" % (first, second)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_in_out_params(first in text, second out text) AS $$ CREATE FUNCTION test_in_out_params(first in text, second out text) AS $$
return first + '_in_to_out'; return first + '_in_to_out';
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_in_out_params_multi(first in text, CREATE FUNCTION test_in_out_params_multi(first in text,
second out text, third out text) AS $$ second out text, third out text) AS $$
return (first + '_record_in_to_out_1', first + '_record_in_to_out_2'); return (first + '_record_in_to_out_1', first + '_record_in_to_out_2');
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_inout_params(first inout text) AS $$ CREATE FUNCTION test_inout_params(first inout text) AS $$
return first + '_inout'; return first + '_inout';
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
-- Test tuple returning functions -- Test tuple returning functions
SELECT * FROM test_table_record_as('dict', null, null, false); SELECT * FROM test_table_record_as('dict', null, null, false);
first | second first | second
@ -340,7 +340,7 @@ SELECT * FROM test_type_record_as('obj', 'one', 1, false);
-- errors cases -- errors cases
CREATE FUNCTION test_type_record_error1() RETURNS type_record AS $$ CREATE FUNCTION test_type_record_error1() RETURNS type_record AS $$
return { 'first': 'first' } return { 'first': 'first' }
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_record_error1(); SELECT * FROM test_type_record_error1();
ERROR: key "second" not found in mapping ERROR: key "second" not found in mapping
HINT: To return null in a column, add the value None to the mapping with the key named after the column. HINT: To return null in a column, add the value None to the mapping with the key named after the column.
@ -348,7 +348,7 @@ CONTEXT: while creating return value
PL/Python function "test_type_record_error1" PL/Python function "test_type_record_error1"
CREATE FUNCTION test_type_record_error2() RETURNS type_record AS $$ CREATE FUNCTION test_type_record_error2() RETURNS type_record AS $$
return [ 'first' ] return [ 'first' ]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_record_error2(); SELECT * FROM test_type_record_error2();
ERROR: length of returned sequence did not match number of columns in row ERROR: length of returned sequence did not match number of columns in row
CONTEXT: while creating return value CONTEXT: while creating return value
@ -357,7 +357,7 @@ CREATE FUNCTION test_type_record_error3() RETURNS type_record AS $$
class type_record: pass class type_record: pass
type_record.first = 'first' type_record.first = 'first'
return type_record return type_record
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_record_error3(); SELECT * FROM test_type_record_error3();
ERROR: attribute "second" does not exist in Python object ERROR: attribute "second" does not exist in Python object
HINT: To return null in a column, let the returned object have an attribute named after column with value None. HINT: To return null in a column, let the returned object have an attribute named after column with value None.
@ -365,7 +365,7 @@ CONTEXT: while creating return value
PL/Python function "test_type_record_error3" PL/Python function "test_type_record_error3"
CREATE FUNCTION test_type_record_error4() RETURNS type_record AS $$ CREATE FUNCTION test_type_record_error4() RETURNS type_record AS $$
return 'foo' return 'foo'
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_record_error4(); SELECT * FROM test_type_record_error4();
ERROR: malformed record literal: "foo" ERROR: malformed record literal: "foo"
DETAIL: Missing left parenthesis. DETAIL: Missing left parenthesis.

View File

@ -3,20 +3,20 @@
-- --
CREATE FUNCTION test_setof_error() RETURNS SETOF text AS $$ CREATE FUNCTION test_setof_error() RETURNS SETOF text AS $$
return 37 return 37
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT test_setof_error(); SELECT test_setof_error();
ERROR: returned object cannot be iterated ERROR: returned object cannot be iterated
DETAIL: PL/Python set-returning functions must return an iterable object. DETAIL: PL/Python set-returning functions must return an iterable object.
CONTEXT: PL/Python function "test_setof_error" CONTEXT: PL/Python function "test_setof_error"
CREATE FUNCTION test_setof_as_list(count integer, content text) RETURNS SETOF text AS $$ CREATE FUNCTION test_setof_as_list(count integer, content text) RETURNS SETOF text AS $$
return [ content ]*count return [ content ]*count
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_setof_as_tuple(count integer, content text) RETURNS SETOF text AS $$ CREATE FUNCTION test_setof_as_tuple(count integer, content text) RETURNS SETOF text AS $$
t = () t = ()
for i in range(count): for i in range(count):
t += ( content, ) t += ( content, )
return t return t
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_setof_as_iterator(count integer, content text) RETURNS SETOF text AS $$ CREATE FUNCTION test_setof_as_iterator(count integer, content text) RETURNS SETOF text AS $$
class producer: class producer:
def __init__ (self, icount, icontent): def __init__ (self, icount, icontent):
@ -24,13 +24,13 @@ class producer:
self.icount = icount self.icount = icount
def __iter__ (self): def __iter__ (self):
return self return self
def next (self): def __next__ (self):
if self.icount == 0: if self.icount == 0:
raise StopIteration raise StopIteration
self.icount -= 1 self.icount -= 1
return self.icontent return self.icontent
return producer(count, content) return producer(count, content)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_setof_spi_in_iterator() RETURNS SETOF text AS CREATE FUNCTION test_setof_spi_in_iterator() RETURNS SETOF text AS
$$ $$
for s in ('Hello', 'Brave', 'New', 'World'): for s in ('Hello', 'Brave', 'New', 'World'):
@ -38,7 +38,7 @@ $$
yield s yield s
plpy.execute('select 2') plpy.execute('select 2')
$$ $$
LANGUAGE plpythonu; LANGUAGE plpython3u;
-- Test set returning functions -- Test set returning functions
SELECT test_setof_as_list(0, 'list'); SELECT test_setof_as_list(0, 'list');
test_setof_as_list test_setof_as_list
@ -130,7 +130,7 @@ global x
while x <= lim: while x <= lim:
yield x yield x
x = x + 1 x = x + 1
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT ugly(1, 5); SELECT ugly(1, 5);
ugly ugly
------ ------
@ -155,7 +155,7 @@ CREATE OR REPLACE FUNCTION get_user_records()
RETURNS SETOF users RETURNS SETOF users
AS $$ AS $$
return plpy.execute("SELECT * FROM users ORDER BY username") return plpy.execute("SELECT * FROM users ORDER BY username")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT get_user_records(); SELECT get_user_records();
get_user_records get_user_records
---------------------- ----------------------
@ -179,7 +179,7 @@ CREATE OR REPLACE FUNCTION get_user_records2()
RETURNS TABLE(fname text, lname text, username text, userid int) RETURNS TABLE(fname text, lname text, username text, userid int)
AS $$ AS $$
return plpy.execute("SELECT * FROM users ORDER BY username") return plpy.execute("SELECT * FROM users ORDER BY username")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT get_user_records2(); SELECT get_user_records2();
get_user_records2 get_user_records2
---------------------- ----------------------

View File

@ -6,17 +6,17 @@ CREATE FUNCTION nested_call_one(a text) RETURNS text
'q = "SELECT nested_call_two(''%s'')" % a 'q = "SELECT nested_call_two(''%s'')" % a
r = plpy.execute(q) r = plpy.execute(q)
return r[0]' return r[0]'
LANGUAGE plpythonu ; LANGUAGE plpython3u ;
CREATE FUNCTION nested_call_two(a text) RETURNS text CREATE FUNCTION nested_call_two(a text) RETURNS text
AS AS
'q = "SELECT nested_call_three(''%s'')" % a 'q = "SELECT nested_call_three(''%s'')" % a
r = plpy.execute(q) r = plpy.execute(q)
return r[0]' return r[0]'
LANGUAGE plpythonu ; LANGUAGE plpython3u ;
CREATE FUNCTION nested_call_three(a text) RETURNS text CREATE FUNCTION nested_call_three(a text) RETURNS text
AS AS
'return a' 'return a'
LANGUAGE plpythonu ; LANGUAGE plpython3u ;
-- some spi stuff -- some spi stuff
CREATE FUNCTION spi_prepared_plan_test_one(a text) RETURNS text CREATE FUNCTION spi_prepared_plan_test_one(a text) RETURNS text
AS AS
@ -30,7 +30,7 @@ except Exception as ex:
plpy.error(str(ex)) plpy.error(str(ex))
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION spi_prepared_plan_test_two(a text) RETURNS text CREATE FUNCTION spi_prepared_plan_test_two(a text) RETURNS text
AS AS
'if "myplan" not in SD: 'if "myplan" not in SD:
@ -43,7 +43,7 @@ except Exception as ex:
plpy.error(str(ex)) plpy.error(str(ex))
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION spi_prepared_plan_test_nested(a text) RETURNS text CREATE FUNCTION spi_prepared_plan_test_nested(a text) RETURNS text
AS AS
'if "myplan" not in SD: 'if "myplan" not in SD:
@ -57,7 +57,7 @@ except Exception as ex:
plpy.error(str(ex)) plpy.error(str(ex))
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION join_sequences(s sequences) RETURNS text CREATE FUNCTION join_sequences(s sequences) RETURNS text
AS AS
'if not s["multipart"]: 'if not s["multipart"]:
@ -69,7 +69,7 @@ for r in rv:
seq = seq + r["sequence"] seq = seq + r["sequence"]
return seq return seq
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION spi_recursive_sum(a int) RETURNS int CREATE FUNCTION spi_recursive_sum(a int) RETURNS int
AS AS
'r = 0 'r = 0
@ -77,7 +77,7 @@ if a > 1:
r = plpy.execute("SELECT spi_recursive_sum(%d) as a" % (a-1))[0]["a"] r = plpy.execute("SELECT spi_recursive_sum(%d) as a" % (a-1))[0]["a"]
return a + r return a + r
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
-- --
-- spi and nested calls -- spi and nested calls
-- --
@ -155,7 +155,7 @@ if result.status() > 0:
return result.nrows() return result.nrows()
else: else:
return None return None
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT result_metadata_test($$SELECT 1 AS foo, '11'::text AS bar UNION SELECT 2, '22'$$); SELECT result_metadata_test($$SELECT 1 AS foo, '11'::text AS bar UNION SELECT 2, '22'$$);
INFO: True INFO: True
INFO: ['foo', 'bar'] INFO: ['foo', 'bar']
@ -177,7 +177,7 @@ CREATE FUNCTION result_nrows_test(cmd text) RETURNS int
AS $$ AS $$
result = plpy.execute(cmd) result = plpy.execute(cmd)
return result.nrows() return result.nrows()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT result_nrows_test($$SELECT 1$$); SELECT result_nrows_test($$SELECT 1$$);
result_nrows_test result_nrows_test
------------------- -------------------
@ -206,7 +206,7 @@ CREATE FUNCTION result_len_test(cmd text) RETURNS int
AS $$ AS $$
result = plpy.execute(cmd) result = plpy.execute(cmd)
return len(result) return len(result)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT result_len_test($$SELECT 1$$); SELECT result_len_test($$SELECT 1$$);
result_len_test result_len_test
----------------- -----------------
@ -246,7 +246,7 @@ result[-1] = {'c': 1000}
result[:2] = [{'c': 10}, {'c': 100}] result[:2] = [{'c': 10}, {'c': 100}]
plpy.info([item['c'] for item in result[:]]) plpy.info([item['c'] for item in result[:]])
# raises TypeError, but the message differs on Python 2.6, so silence it # raises TypeError, catch so further tests could be added
try: try:
plpy.info(result['foo']) plpy.info(result['foo'])
except TypeError: except TypeError:
@ -254,7 +254,7 @@ except TypeError:
else: else:
assert False, "TypeError not raised" assert False, "TypeError not raised"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT result_subscript_test(); SELECT result_subscript_test();
INFO: 2 INFO: 2
INFO: 4 INFO: 4
@ -272,7 +272,7 @@ result = plpy.execute("select 1 where false")
plpy.info(result[:]) plpy.info(result[:])
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT result_empty_test(); SELECT result_empty_test();
INFO: [] INFO: []
result_empty_test result_empty_test
@ -285,7 +285,7 @@ AS $$
plan = plpy.prepare(cmd) plan = plpy.prepare(cmd)
result = plpy.execute(plan) result = plpy.execute(plan)
return str(result) return str(result)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT result_str_test($$SELECT 1 AS foo UNION SELECT 2$$); SELECT result_str_test($$SELECT 1 AS foo UNION SELECT 2$$);
result_str_test result_str_test
------------------------------------------------------------ ------------------------------------------------------------
@ -306,12 +306,12 @@ for row in res:
if row['lname'] == 'doe': if row['lname'] == 'doe':
does += 1 does += 1
return does return does
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION double_cursor_close() RETURNS int AS $$ CREATE FUNCTION double_cursor_close() RETURNS int AS $$
res = plpy.cursor("select fname, lname from users") res = plpy.cursor("select fname, lname from users")
res.close() res.close()
res.close() res.close()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_fetch() RETURNS int AS $$ CREATE FUNCTION cursor_fetch() RETURNS int AS $$
res = plpy.cursor("select fname, lname from users") res = plpy.cursor("select fname, lname from users")
assert len(res.fetch(3)) == 3 assert len(res.fetch(3)) == 3
@ -329,7 +329,7 @@ except StopIteration:
pass pass
else: else:
assert False, "StopIteration not raised" assert False, "StopIteration not raised"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_mix_next_and_fetch() RETURNS int AS $$ CREATE FUNCTION cursor_mix_next_and_fetch() RETURNS int AS $$
res = plpy.cursor("select fname, lname from users order by fname") res = plpy.cursor("select fname, lname from users order by fname")
assert len(res.fetch(2)) == 2 assert len(res.fetch(2)) == 2
@ -342,7 +342,7 @@ except AttributeError:
assert item['fname'] == 'rick' assert item['fname'] == 'rick'
assert len(res.fetch(2)) == 1 assert len(res.fetch(2)) == 1
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION fetch_after_close() RETURNS int AS $$ CREATE FUNCTION fetch_after_close() RETURNS int AS $$
res = plpy.cursor("select fname, lname from users") res = plpy.cursor("select fname, lname from users")
res.close() res.close()
@ -352,7 +352,7 @@ except ValueError:
pass pass
else: else:
assert False, "ValueError not raised" assert False, "ValueError not raised"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION next_after_close() RETURNS int AS $$ CREATE FUNCTION next_after_close() RETURNS int AS $$
res = plpy.cursor("select fname, lname from users") res = plpy.cursor("select fname, lname from users")
res.close() res.close()
@ -365,7 +365,7 @@ except ValueError:
pass pass
else: else:
assert False, "ValueError not raised" assert False, "ValueError not raised"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_fetch_next_empty() RETURNS int AS $$ CREATE FUNCTION cursor_fetch_next_empty() RETURNS int AS $$
res = plpy.cursor("select fname, lname from users where false") res = plpy.cursor("select fname, lname from users where false")
assert len(res.fetch(1)) == 0 assert len(res.fetch(1)) == 0
@ -378,7 +378,7 @@ except StopIteration:
pass pass
else: else:
assert False, "StopIteration not raised" assert False, "StopIteration not raised"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_plan() RETURNS SETOF text AS $$ CREATE FUNCTION cursor_plan() RETURNS SETOF text AS $$
plan = plpy.prepare( plan = plpy.prepare(
"select fname, lname from users where fname like $1 || '%' order by fname", "select fname, lname from users where fname like $1 || '%' order by fname",
@ -387,12 +387,12 @@ for row in plpy.cursor(plan, ["w"]):
yield row['fname'] yield row['fname']
for row in plan.cursor(["j"]): for row in plan.cursor(["j"]):
yield row['fname'] yield row['fname']
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_plan_wrong_args() RETURNS SETOF text AS $$ CREATE FUNCTION cursor_plan_wrong_args() RETURNS SETOF text AS $$
plan = plpy.prepare("select fname, lname from users where fname like $1 || '%'", plan = plpy.prepare("select fname, lname from users where fname like $1 || '%'",
["text"]) ["text"])
c = plpy.cursor(plan, ["a", "b"]) c = plpy.cursor(plan, ["a", "b"])
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TYPE test_composite_type AS ( CREATE TYPE test_composite_type AS (
a1 int, a1 int,
a2 varchar a2 varchar
@ -401,7 +401,7 @@ CREATE OR REPLACE FUNCTION plan_composite_args() RETURNS test_composite_type AS
plan = plpy.prepare("select $1 as c1", ["test_composite_type"]) plan = plpy.prepare("select $1 as c1", ["test_composite_type"])
res = plpy.execute(plan, [{"a1": 3, "a2": "label"}]) res = plpy.execute(plan, [{"a1": 3, "a2": "label"}])
return res[0]["c1"] return res[0]["c1"]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT simple_cursor_test(); SELECT simple_cursor_test();
simple_cursor_test simple_cursor_test
-------------------- --------------------

View File

@ -14,7 +14,7 @@ with plpy.subtransaction():
plpy.execute("INSERT INTO subtransaction_tbl VALUES ('oops')") plpy.execute("INSERT INTO subtransaction_tbl VALUES ('oops')")
elif what_error == "Python": elif what_error == "Python":
raise Exception("Python exception") raise Exception("Python exception")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT subtransaction_ctx_test(); SELECT subtransaction_ctx_test();
subtransaction_ctx_test subtransaction_ctx_test
------------------------- -------------------------
@ -71,7 +71,7 @@ with plpy.subtransaction():
raise raise
plpy.notice("Swallowed %s(%r)" % (e.__class__.__name__, e.args[0])) plpy.notice("Swallowed %s(%r)" % (e.__class__.__name__, e.args[0]))
return "ok" return "ok"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT subtransaction_nested_test(); SELECT subtransaction_nested_test();
ERROR: spiexceptions.SyntaxError: syntax error at or near "error" ERROR: spiexceptions.SyntaxError: syntax error at or near "error"
LINE 1: error LINE 1: error
@ -111,7 +111,7 @@ with plpy.subtransaction():
plpy.execute("INSERT INTO subtransaction_tbl VALUES (2)") plpy.execute("INSERT INTO subtransaction_tbl VALUES (2)")
plpy.execute("SELECT subtransaction_nested_test('t')") plpy.execute("SELECT subtransaction_nested_test('t')")
return "ok" return "ok"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT subtransaction_deeply_nested_test(); SELECT subtransaction_deeply_nested_test();
NOTICE: Swallowed SyntaxError('syntax error at or near "error"') NOTICE: Swallowed SyntaxError('syntax error at or near "error"')
subtransaction_deeply_nested_test subtransaction_deeply_nested_test
@ -133,42 +133,42 @@ TRUNCATE subtransaction_tbl;
CREATE FUNCTION subtransaction_exit_without_enter() RETURNS void CREATE FUNCTION subtransaction_exit_without_enter() RETURNS void
AS $$ AS $$
plpy.subtransaction().__exit__(None, None, None) plpy.subtransaction().__exit__(None, None, None)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION subtransaction_enter_without_exit() RETURNS void CREATE FUNCTION subtransaction_enter_without_exit() RETURNS void
AS $$ AS $$
plpy.subtransaction().__enter__() plpy.subtransaction().__enter__()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION subtransaction_exit_twice() RETURNS void CREATE FUNCTION subtransaction_exit_twice() RETURNS void
AS $$ AS $$
plpy.subtransaction().__enter__() plpy.subtransaction().__enter__()
plpy.subtransaction().__exit__(None, None, None) plpy.subtransaction().__exit__(None, None, None)
plpy.subtransaction().__exit__(None, None, None) plpy.subtransaction().__exit__(None, None, None)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION subtransaction_enter_twice() RETURNS void CREATE FUNCTION subtransaction_enter_twice() RETURNS void
AS $$ AS $$
plpy.subtransaction().__enter__() plpy.subtransaction().__enter__()
plpy.subtransaction().__enter__() plpy.subtransaction().__enter__()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION subtransaction_exit_same_subtransaction_twice() RETURNS void CREATE FUNCTION subtransaction_exit_same_subtransaction_twice() RETURNS void
AS $$ AS $$
s = plpy.subtransaction() s = plpy.subtransaction()
s.__enter__() s.__enter__()
s.__exit__(None, None, None) s.__exit__(None, None, None)
s.__exit__(None, None, None) s.__exit__(None, None, None)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION subtransaction_enter_same_subtransaction_twice() RETURNS void CREATE FUNCTION subtransaction_enter_same_subtransaction_twice() RETURNS void
AS $$ AS $$
s = plpy.subtransaction() s = plpy.subtransaction()
s.__enter__() s.__enter__()
s.__enter__() s.__enter__()
s.__exit__(None, None, None) s.__exit__(None, None, None)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
-- No warnings here, as the subtransaction gets indeed closed -- No warnings here, as the subtransaction gets indeed closed
CREATE FUNCTION subtransaction_enter_subtransaction_in_with() RETURNS void CREATE FUNCTION subtransaction_enter_subtransaction_in_with() RETURNS void
AS $$ AS $$
with plpy.subtransaction() as s: with plpy.subtransaction() as s:
s.__enter__() s.__enter__()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION subtransaction_exit_subtransaction_in_with() RETURNS void CREATE FUNCTION subtransaction_exit_subtransaction_in_with() RETURNS void
AS $$ AS $$
try: try:
@ -176,7 +176,7 @@ try:
s.__exit__(None, None, None) s.__exit__(None, None, None)
except ValueError as e: except ValueError as e:
raise ValueError(e) raise ValueError(e)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT subtransaction_exit_without_enter(); SELECT subtransaction_exit_without_enter();
ERROR: ValueError: this subtransaction has not been entered ERROR: ValueError: this subtransaction has not been entered
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
@ -255,7 +255,7 @@ try:
plpy.execute(p, ["wrong"]) plpy.execute(p, ["wrong"])
except plpy.SPIError: except plpy.SPIError:
plpy.warning("Caught a SPI error") plpy.warning("Caught a SPI error")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT subtransaction_mix_explicit_and_implicit(); SELECT subtransaction_mix_explicit_and_implicit();
WARNING: Caught a SPI error from an explicit subtransaction WARNING: Caught a SPI error from an explicit subtransaction
WARNING: Caught a SPI error WARNING: Caught a SPI error
@ -278,7 +278,7 @@ AS $$
s = plpy.subtransaction() s = plpy.subtransaction()
s.enter() s.enter()
s.exit(None, None, None) s.exit(None, None, None)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT subtransaction_alternative_names(); SELECT subtransaction_alternative_names();
subtransaction_alternative_names subtransaction_alternative_names
---------------------------------- ----------------------------------
@ -294,7 +294,7 @@ with plpy.subtransaction():
plpy.execute("INSERT INTO subtransaction_tbl VALUES ('a')") plpy.execute("INSERT INTO subtransaction_tbl VALUES ('a')")
except plpy.SPIError: except plpy.SPIError:
plpy.notice("caught") plpy.notice("caught")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT try_catch_inside_subtransaction(); SELECT try_catch_inside_subtransaction();
NOTICE: caught NOTICE: caught
try_catch_inside_subtransaction try_catch_inside_subtransaction
@ -318,7 +318,7 @@ with plpy.subtransaction():
plpy.execute("INSERT INTO subtransaction_tbl VALUES (1)") plpy.execute("INSERT INTO subtransaction_tbl VALUES (1)")
except plpy.SPIError: except plpy.SPIError:
plpy.notice("caught") plpy.notice("caught")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT pk_violation_inside_subtransaction(); SELECT pk_violation_inside_subtransaction();
NOTICE: caught NOTICE: caught
pk_violation_inside_subtransaction pk_violation_inside_subtransaction
@ -340,7 +340,7 @@ with plpy.subtransaction():
cur.fetch(10) cur.fetch(10)
fetched = cur.fetch(10); fetched = cur.fetch(10);
return int(fetched[5]["i"]) return int(fetched[5]["i"])
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_aborted_subxact() RETURNS int AS $$ CREATE FUNCTION cursor_aborted_subxact() RETURNS int AS $$
try: try:
with plpy.subtransaction(): with plpy.subtransaction():
@ -351,7 +351,7 @@ except plpy.SPIError:
fetched = cur.fetch(10) fetched = cur.fetch(10)
return int(fetched[5]["i"]) return int(fetched[5]["i"])
return 0 # not reached return 0 # not reached
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_plan_aborted_subxact() RETURNS int AS $$ CREATE FUNCTION cursor_plan_aborted_subxact() RETURNS int AS $$
try: try:
with plpy.subtransaction(): with plpy.subtransaction():
@ -364,7 +364,7 @@ except plpy.SPIError:
fetched = cur.fetch(5) fetched = cur.fetch(5)
return fetched[2]["i"] return fetched[2]["i"]
return 0 # not reached return 0 # not reached
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_close_aborted_subxact() RETURNS boolean AS $$ CREATE FUNCTION cursor_close_aborted_subxact() RETURNS boolean AS $$
try: try:
with plpy.subtransaction(): with plpy.subtransaction():
@ -374,7 +374,7 @@ except plpy.SPIError:
cur.close() cur.close()
return True return True
return False # not reached return False # not reached
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT cursor_in_subxact(); SELECT cursor_in_subxact();
cursor_in_subxact cursor_in_subxact
------------------- -------------------

View File

@ -1,7 +1,7 @@
-- first some tests of basic functionality -- first some tests of basic functionality
CREATE EXTENSION plpython2u; CREATE EXTENSION plpython3u;
-- really stupid function just to get the module loaded -- really stupid function just to get the module loaded
CREATE FUNCTION stupid() RETURNS text AS 'return "zarkon"' LANGUAGE plpythonu; CREATE FUNCTION stupid() RETURNS text AS 'return "zarkon"' LANGUAGE plpython3u;
select stupid(); select stupid();
stupid stupid
-------- --------
@ -9,7 +9,7 @@ select stupid();
(1 row) (1 row)
-- check 2/3 versioning -- check 2/3 versioning
CREATE FUNCTION stupidn() RETURNS text AS 'return "zarkon"' LANGUAGE plpython2u; CREATE FUNCTION stupidn() RETURNS text AS 'return "zarkon"' LANGUAGE plpython3u;
select stupidn(); select stupidn();
stupidn stupidn
--------- ---------
@ -26,7 +26,7 @@ for key in keys:
out.append("%s: %s" % (key, u[key])) out.append("%s: %s" % (key, u[key]))
words = a1 + " " + a2 + " => {" + ", ".join(out) + "}" words = a1 + " " + a2 + " => {" + ", ".join(out) + "}"
return words' return words'
LANGUAGE plpythonu; LANGUAGE plpython3u;
select "Argument test #1"(users, fname, lname) from users where lname = 'doe' order by 1; select "Argument test #1"(users, fname, lname) from users where lname = 'doe' order by 1;
Argument test #1 Argument test #1
----------------------------------------------------------------------- -----------------------------------------------------------------------
@ -41,7 +41,7 @@ $$
contents = list(filter(lambda x: not x.startswith("__"), dir(plpy))) contents = list(filter(lambda x: not x.startswith("__"), dir(plpy)))
contents.sort() contents.sort()
return contents return contents
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
select module_contents(); select module_contents();
module_contents module_contents
----------------- -----------------
@ -78,7 +78,7 @@ plpy.info('info', 37, [1, 2, 3])
plpy.notice('notice') plpy.notice('notice')
plpy.warning('warning') plpy.warning('warning')
plpy.error('error') plpy.error('error')
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT elog_test_basic(); SELECT elog_test_basic();
INFO: info INFO: info
INFO: 37 INFO: 37

View File

@ -1,6 +1,6 @@
CREATE TABLE test1 (a int, b text); CREATE TABLE test1 (a int, b text);
CREATE PROCEDURE transaction_test1() CREATE PROCEDURE transaction_test1()
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
for i in range(0, 10): for i in range(0, 10):
plpy.execute("INSERT INTO test1 (a) VALUES (%d)" % i) plpy.execute("INSERT INTO test1 (a) VALUES (%d)" % i)
@ -22,7 +22,7 @@ SELECT * FROM test1;
TRUNCATE test1; TRUNCATE test1;
DO DO
LANGUAGE plpythonu LANGUAGE plpython3u
$$ $$
for i in range(0, 10): for i in range(0, 10):
plpy.execute("INSERT INTO test1 (a) VALUES (%d)" % i) plpy.execute("INSERT INTO test1 (a) VALUES (%d)" % i)
@ -44,7 +44,7 @@ SELECT * FROM test1;
TRUNCATE test1; TRUNCATE test1;
-- not allowed in a function -- not allowed in a function
CREATE FUNCTION transaction_test2() RETURNS int CREATE FUNCTION transaction_test2() RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
for i in range(0, 10): for i in range(0, 10):
plpy.execute("INSERT INTO test1 (a) VALUES (%d)" % i) plpy.execute("INSERT INTO test1 (a) VALUES (%d)" % i)
@ -67,7 +67,7 @@ SELECT * FROM test1;
-- also not allowed if procedure is called from a function -- also not allowed if procedure is called from a function
CREATE FUNCTION transaction_test3() RETURNS int CREATE FUNCTION transaction_test3() RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plpy.execute("CALL transaction_test1()") plpy.execute("CALL transaction_test1()")
return 1 return 1
@ -85,19 +85,19 @@ SELECT * FROM test1;
-- DO block inside function -- DO block inside function
CREATE FUNCTION transaction_test4() RETURNS int CREATE FUNCTION transaction_test4() RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plpy.execute("DO LANGUAGE plpythonu $x$ plpy.commit() $x$") plpy.execute("DO LANGUAGE plpython3u $x$ plpy.commit() $x$")
return 1 return 1
$$; $$;
SELECT transaction_test4(); SELECT transaction_test4();
ERROR: spiexceptions.InvalidTransactionTermination: spiexceptions.InvalidTransactionTermination: invalid transaction termination ERROR: spiexceptions.InvalidTransactionTermination: spiexceptions.InvalidTransactionTermination: invalid transaction termination
CONTEXT: Traceback (most recent call last): CONTEXT: Traceback (most recent call last):
PL/Python function "transaction_test4", line 2, in <module> PL/Python function "transaction_test4", line 2, in <module>
plpy.execute("DO LANGUAGE plpythonu $x$ plpy.commit() $x$") plpy.execute("DO LANGUAGE plpython3u $x$ plpy.commit() $x$")
PL/Python function "transaction_test4" PL/Python function "transaction_test4"
-- commit inside subtransaction (prohibited) -- commit inside subtransaction (prohibited)
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
s = plpy.subtransaction() s = plpy.subtransaction()
s.enter() s.enter()
plpy.commit() plpy.commit()
@ -112,7 +112,7 @@ PL/Python anonymous code block
CREATE TABLE test2 (x int); CREATE TABLE test2 (x int);
INSERT INTO test2 VALUES (0), (1), (2), (3), (4); INSERT INTO test2 VALUES (0), (1), (2), (3), (4);
TRUNCATE test1; TRUNCATE test1;
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"): for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"):
plpy.execute("INSERT INTO test1 (a) VALUES (%s)" % row['x']) plpy.execute("INSERT INTO test1 (a) VALUES (%s)" % row['x'])
plpy.commit() plpy.commit()
@ -135,7 +135,7 @@ SELECT * FROM pg_cursors;
-- error in cursor loop with commit -- error in cursor loop with commit
TRUNCATE test1; TRUNCATE test1;
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"): for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"):
plpy.execute("INSERT INTO test1 (a) VALUES (12/(%s-2))" % row['x']) plpy.execute("INSERT INTO test1 (a) VALUES (12/(%s-2))" % row['x'])
plpy.commit() plpy.commit()
@ -159,7 +159,7 @@ SELECT * FROM pg_cursors;
-- rollback inside cursor loop -- rollback inside cursor loop
TRUNCATE test1; TRUNCATE test1;
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"): for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"):
plpy.execute("INSERT INTO test1 (a) VALUES (%s)" % row['x']) plpy.execute("INSERT INTO test1 (a) VALUES (%s)" % row['x'])
plpy.rollback() plpy.rollback()
@ -176,7 +176,7 @@ SELECT * FROM pg_cursors;
-- first commit then rollback inside cursor loop -- first commit then rollback inside cursor loop
TRUNCATE test1; TRUNCATE test1;
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"): for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"):
plpy.execute("INSERT INTO test1 (a) VALUES (%s)" % row['x']) plpy.execute("INSERT INTO test1 (a) VALUES (%s)" % row['x'])
if row['x'] % 2 == 0: if row['x'] % 2 == 0:
@ -200,7 +200,7 @@ SELECT * FROM pg_cursors;
-- check handling of an error during COMMIT -- check handling of an error during COMMIT
CREATE TABLE testpk (id int PRIMARY KEY); CREATE TABLE testpk (id int PRIMARY KEY);
CREATE TABLE testfk(f1 int REFERENCES testpk DEFERRABLE INITIALLY DEFERRED); CREATE TABLE testfk(f1 int REFERENCES testpk DEFERRABLE INITIALLY DEFERRED);
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
# this insert will fail during commit: # this insert will fail during commit:
plpy.execute("INSERT INTO testfk VALUES (0)") plpy.execute("INSERT INTO testfk VALUES (0)")
plpy.commit() plpy.commit()
@ -222,7 +222,7 @@ SELECT * FROM testfk;
---- ----
(0 rows) (0 rows)
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
# this insert will fail during commit: # this insert will fail during commit:
plpy.execute("INSERT INTO testfk VALUES (0)") plpy.execute("INSERT INTO testfk VALUES (0)")
try: try:

View File

@ -15,20 +15,20 @@ if TD["new"]["fname"] == "william":
TD["new"]["fname"] = TD["args"][0] TD["new"]["fname"] = TD["args"][0]
rv = "MODIFY" rv = "MODIFY"
return rv' return rv'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION users_update() returns trigger CREATE FUNCTION users_update() returns trigger
AS AS
'if TD["event"] == "UPDATE": 'if TD["event"] == "UPDATE":
if TD["old"]["fname"] != TD["new"]["fname"] and TD["old"]["fname"] == TD["args"][0]: if TD["old"]["fname"] != TD["new"]["fname"] and TD["old"]["fname"] == TD["args"][0]:
return "SKIP" return "SKIP"
return None' return None'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION users_delete() RETURNS trigger CREATE FUNCTION users_delete() RETURNS trigger
AS AS
'if TD["old"]["fname"] == TD["args"][0]: 'if TD["old"]["fname"] == TD["args"][0]:
return "SKIP" return "SKIP"
return None' return None'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE TRIGGER users_insert_trig BEFORE INSERT ON users FOR EACH ROW CREATE TRIGGER users_insert_trig BEFORE INSERT ON users FOR EACH ROW
EXECUTE PROCEDURE users_insert ('willem'); EXECUTE PROCEDURE users_insert ('willem');
CREATE TRIGGER users_update_trig BEFORE UPDATE ON users FOR EACH ROW CREATE TRIGGER users_update_trig BEFORE UPDATE ON users FOR EACH ROW
@ -71,7 +71,7 @@ CREATE TABLE trigger_test_generated (
i int, i int,
j int GENERATED ALWAYS AS (i * 2) STORED j int GENERATED ALWAYS AS (i * 2) STORED
); );
CREATE FUNCTION trigger_data() RETURNS trigger LANGUAGE plpythonu AS $$ CREATE FUNCTION trigger_data() RETURNS trigger LANGUAGE plpython3u AS $$
if 'relid' in TD: if 'relid' in TD:
TD['relid'] = "bogus:12345" TD['relid'] = "bogus:12345"
@ -328,7 +328,7 @@ INSERT INTO trigger_test VALUES (0, 'zero');
CREATE FUNCTION stupid1() RETURNS trigger CREATE FUNCTION stupid1() RETURNS trigger
AS $$ AS $$
return 37 return 37
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger1 CREATE TRIGGER stupid_trigger1
BEFORE INSERT ON trigger_test BEFORE INSERT ON trigger_test
FOR EACH ROW EXECUTE PROCEDURE stupid1(); FOR EACH ROW EXECUTE PROCEDURE stupid1();
@ -341,7 +341,7 @@ DROP TRIGGER stupid_trigger1 ON trigger_test;
CREATE FUNCTION stupid2() RETURNS trigger CREATE FUNCTION stupid2() RETURNS trigger
AS $$ AS $$
return "MODIFY" return "MODIFY"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger2 CREATE TRIGGER stupid_trigger2
BEFORE DELETE ON trigger_test BEFORE DELETE ON trigger_test
FOR EACH ROW EXECUTE PROCEDURE stupid2(); FOR EACH ROW EXECUTE PROCEDURE stupid2();
@ -353,7 +353,7 @@ INSERT INTO trigger_test VALUES (0, 'zero');
CREATE FUNCTION stupid3() RETURNS trigger CREATE FUNCTION stupid3() RETURNS trigger
AS $$ AS $$
return "foo" return "foo"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger3 CREATE TRIGGER stupid_trigger3
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
FOR EACH ROW EXECUTE PROCEDURE stupid3(); FOR EACH ROW EXECUTE PROCEDURE stupid3();
@ -365,8 +365,8 @@ DROP TRIGGER stupid_trigger3 ON trigger_test;
-- Unicode variant -- Unicode variant
CREATE FUNCTION stupid3u() RETURNS trigger CREATE FUNCTION stupid3u() RETURNS trigger
AS $$ AS $$
return u"foo" return "foo"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger3 CREATE TRIGGER stupid_trigger3
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
FOR EACH ROW EXECUTE PROCEDURE stupid3u(); FOR EACH ROW EXECUTE PROCEDURE stupid3u();
@ -380,7 +380,7 @@ CREATE FUNCTION stupid4() RETURNS trigger
AS $$ AS $$
del TD["new"] del TD["new"]
return "MODIFY"; return "MODIFY";
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger4 CREATE TRIGGER stupid_trigger4
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
FOR EACH ROW EXECUTE PROCEDURE stupid4(); FOR EACH ROW EXECUTE PROCEDURE stupid4();
@ -394,7 +394,7 @@ CREATE FUNCTION stupid5() RETURNS trigger
AS $$ AS $$
TD["new"] = ['foo', 'bar'] TD["new"] = ['foo', 'bar']
return "MODIFY"; return "MODIFY";
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger5 CREATE TRIGGER stupid_trigger5
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
FOR EACH ROW EXECUTE PROCEDURE stupid5(); FOR EACH ROW EXECUTE PROCEDURE stupid5();
@ -408,7 +408,7 @@ CREATE FUNCTION stupid6() RETURNS trigger
AS $$ AS $$
TD["new"] = {1: 'foo', 2: 'bar'} TD["new"] = {1: 'foo', 2: 'bar'}
return "MODIFY"; return "MODIFY";
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger6 CREATE TRIGGER stupid_trigger6
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
FOR EACH ROW EXECUTE PROCEDURE stupid6(); FOR EACH ROW EXECUTE PROCEDURE stupid6();
@ -422,7 +422,7 @@ CREATE FUNCTION stupid7() RETURNS trigger
AS $$ AS $$
TD["new"] = {'v': 'foo', 'a': 'bar'} TD["new"] = {'v': 'foo', 'a': 'bar'}
return "MODIFY"; return "MODIFY";
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger7 CREATE TRIGGER stupid_trigger7
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
FOR EACH ROW EXECUTE PROCEDURE stupid7(); FOR EACH ROW EXECUTE PROCEDURE stupid7();
@ -434,9 +434,9 @@ DROP TRIGGER stupid_trigger7 ON trigger_test;
-- Unicode variant -- Unicode variant
CREATE FUNCTION stupid7u() RETURNS trigger CREATE FUNCTION stupid7u() RETURNS trigger
AS $$ AS $$
TD["new"] = {u'v': 'foo', u'a': 'bar'} TD["new"] = {'v': 'foo', 'a': 'bar'}
return "MODIFY" return "MODIFY"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger7 CREATE TRIGGER stupid_trigger7
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
FOR EACH ROW EXECUTE PROCEDURE stupid7u(); FOR EACH ROW EXECUTE PROCEDURE stupid7u();
@ -461,7 +461,7 @@ CREATE FUNCTION test_null() RETURNS trigger
AS $$ AS $$
TD["new"]['v'] = None TD["new"]['v'] = None
return "MODIFY" return "MODIFY"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER test_null_trigger CREATE TRIGGER test_null_trigger
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
FOR EACH ROW EXECUTE PROCEDURE test_null(); FOR EACH ROW EXECUTE PROCEDURE test_null();
@ -481,7 +481,7 @@ SET DateStyle = 'ISO';
CREATE FUNCTION set_modif_time() RETURNS trigger AS $$ CREATE FUNCTION set_modif_time() RETURNS trigger AS $$
TD['new']['modif_time'] = '2010-10-13 21:57:28.930486' TD['new']['modif_time'] = '2010-10-13 21:57:28.930486'
return 'MODIFY' return 'MODIFY'
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TABLE pb (a TEXT, modif_time TIMESTAMP(0) WITHOUT TIME ZONE); CREATE TABLE pb (a TEXT, modif_time TIMESTAMP(0) WITHOUT TIME ZONE);
CREATE TRIGGER set_modif_time BEFORE UPDATE ON pb CREATE TRIGGER set_modif_time BEFORE UPDATE ON pb
FOR EACH ROW EXECUTE PROCEDURE set_modif_time(); FOR EACH ROW EXECUTE PROCEDURE set_modif_time();
@ -507,7 +507,7 @@ CREATE FUNCTION composite_trigger_f() RETURNS trigger AS $$
TD['new']['f1'] = (3, False) TD['new']['f1'] = (3, False)
TD['new']['f2'] = {'k': 7, 'l': 'yes', 'ignored': 10} TD['new']['f2'] = {'k': 7, 'l': 'yes', 'ignored': 10}
return 'MODIFY' return 'MODIFY'
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER composite_trigger BEFORE INSERT ON composite_trigger_test CREATE TRIGGER composite_trigger BEFORE INSERT ON composite_trigger_test
FOR EACH ROW EXECUTE PROCEDURE composite_trigger_f(); FOR EACH ROW EXECUTE PROCEDURE composite_trigger_f();
INSERT INTO composite_trigger_test VALUES (NULL, NULL); INSERT INTO composite_trigger_test VALUES (NULL, NULL);
@ -521,7 +521,7 @@ SELECT * FROM composite_trigger_test;
CREATE TABLE composite_trigger_noop_test (f1 comp1, f2 comp2); CREATE TABLE composite_trigger_noop_test (f1 comp1, f2 comp2);
CREATE FUNCTION composite_trigger_noop_f() RETURNS trigger AS $$ CREATE FUNCTION composite_trigger_noop_f() RETURNS trigger AS $$
return 'MODIFY' return 'MODIFY'
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER composite_trigger_noop BEFORE INSERT ON composite_trigger_noop_test CREATE TRIGGER composite_trigger_noop BEFORE INSERT ON composite_trigger_noop_test
FOR EACH ROW EXECUTE PROCEDURE composite_trigger_noop_f(); FOR EACH ROW EXECUTE PROCEDURE composite_trigger_noop_f();
INSERT INTO composite_trigger_noop_test VALUES (NULL, NULL); INSERT INTO composite_trigger_noop_test VALUES (NULL, NULL);
@ -540,7 +540,7 @@ CREATE TYPE comp3 AS (c1 comp1, c2 comp2, m integer);
CREATE TABLE composite_trigger_nested_test(c comp3); CREATE TABLE composite_trigger_nested_test(c comp3);
CREATE FUNCTION composite_trigger_nested_f() RETURNS trigger AS $$ CREATE FUNCTION composite_trigger_nested_f() RETURNS trigger AS $$
return 'MODIFY' return 'MODIFY'
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER composite_trigger_nested BEFORE INSERT ON composite_trigger_nested_test CREATE TRIGGER composite_trigger_nested BEFORE INSERT ON composite_trigger_nested_test
FOR EACH ROW EXECUTE PROCEDURE composite_trigger_nested_f(); FOR EACH ROW EXECUTE PROCEDURE composite_trigger_nested_f();
INSERT INTO composite_trigger_nested_test VALUES (NULL); INSERT INTO composite_trigger_nested_test VALUES (NULL);
@ -555,7 +555,7 @@ SELECT * FROM composite_trigger_nested_test;
(3 rows) (3 rows)
-- check that using a function as a trigger over two tables works correctly -- check that using a function as a trigger over two tables works correctly
CREATE FUNCTION trig1234() RETURNS trigger LANGUAGE plpythonu AS $$ CREATE FUNCTION trig1234() RETURNS trigger LANGUAGE plpython3u AS $$
TD["new"]["data"] = '1234' TD["new"]["data"] = '1234'
return 'MODIFY' return 'MODIFY'
$$; $$;
@ -581,7 +581,7 @@ SELECT * FROM b;
-- check that SQL run in trigger code can see transition tables -- check that SQL run in trigger code can see transition tables
CREATE TABLE transition_table_test (id int, name text); CREATE TABLE transition_table_test (id int, name text);
INSERT INTO transition_table_test VALUES (1, 'a'); INSERT INTO transition_table_test VALUES (1, 'a');
CREATE FUNCTION transition_table_test_f() RETURNS trigger LANGUAGE plpythonu AS CREATE FUNCTION transition_table_test_f() RETURNS trigger LANGUAGE plpython3u AS
$$ $$
rv = plpy.execute("SELECT * FROM old_table") rv = plpy.execute("SELECT * FROM old_table")
assert(rv.nrows() == 1) assert(rv.nrows() == 1)
@ -601,7 +601,7 @@ DROP TABLE transition_table_test;
DROP FUNCTION transition_table_test_f(); DROP FUNCTION transition_table_test_f();
-- dealing with generated columns -- dealing with generated columns
CREATE FUNCTION generated_test_func1() RETURNS trigger CREATE FUNCTION generated_test_func1() RETURNS trigger
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
TD['new']['j'] = 5 # not allowed TD['new']['j'] = 5 # not allowed
return 'MODIFY' return 'MODIFY'

View File

@ -7,23 +7,23 @@
CREATE FUNCTION test_type_conversion_bool(x bool) RETURNS bool AS $$ CREATE FUNCTION test_type_conversion_bool(x bool) RETURNS bool AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_bool(true); SELECT * FROM test_type_conversion_bool(true);
INFO: (True, <type 'bool'>) INFO: (True, <class 'bool'>)
test_type_conversion_bool test_type_conversion_bool
--------------------------- ---------------------------
t t
(1 row) (1 row)
SELECT * FROM test_type_conversion_bool(false); SELECT * FROM test_type_conversion_bool(false);
INFO: (False, <type 'bool'>) INFO: (False, <class 'bool'>)
test_type_conversion_bool test_type_conversion_bool
--------------------------- ---------------------------
f f
(1 row) (1 row)
SELECT * FROM test_type_conversion_bool(null); SELECT * FROM test_type_conversion_bool(null);
INFO: (None, <type 'NoneType'>) INFO: (None, <class 'NoneType'>)
test_type_conversion_bool test_type_conversion_bool
--------------------------- ---------------------------
@ -48,7 +48,7 @@ elif n == 5:
ret = [0] ret = [0]
plpy.info(ret, not not ret) plpy.info(ret, not not ret)
return ret return ret
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_bool_other(0); SELECT * FROM test_type_conversion_bool_other(0);
INFO: (0, False) INFO: (0, False)
test_type_conversion_bool_other test_type_conversion_bool_other
@ -94,16 +94,16 @@ INFO: ([0], True)
CREATE FUNCTION test_type_conversion_char(x char) RETURNS char AS $$ CREATE FUNCTION test_type_conversion_char(x char) RETURNS char AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_char('a'); SELECT * FROM test_type_conversion_char('a');
INFO: ('a', <type 'str'>) INFO: ('a', <class 'str'>)
test_type_conversion_char test_type_conversion_char
--------------------------- ---------------------------
a a
(1 row) (1 row)
SELECT * FROM test_type_conversion_char(null); SELECT * FROM test_type_conversion_char(null);
INFO: (None, <type 'NoneType'>) INFO: (None, <class 'NoneType'>)
test_type_conversion_char test_type_conversion_char
--------------------------- ---------------------------
@ -112,23 +112,23 @@ INFO: (None, <type 'NoneType'>)
CREATE FUNCTION test_type_conversion_int2(x int2) RETURNS int2 AS $$ CREATE FUNCTION test_type_conversion_int2(x int2) RETURNS int2 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_int2(100::int2); SELECT * FROM test_type_conversion_int2(100::int2);
INFO: (100, <type 'int'>) INFO: (100, <class 'int'>)
test_type_conversion_int2 test_type_conversion_int2
--------------------------- ---------------------------
100 100
(1 row) (1 row)
SELECT * FROM test_type_conversion_int2(-100::int2); SELECT * FROM test_type_conversion_int2(-100::int2);
INFO: (-100, <type 'int'>) INFO: (-100, <class 'int'>)
test_type_conversion_int2 test_type_conversion_int2
--------------------------- ---------------------------
-100 -100
(1 row) (1 row)
SELECT * FROM test_type_conversion_int2(null); SELECT * FROM test_type_conversion_int2(null);
INFO: (None, <type 'NoneType'>) INFO: (None, <class 'NoneType'>)
test_type_conversion_int2 test_type_conversion_int2
--------------------------- ---------------------------
@ -137,23 +137,23 @@ INFO: (None, <type 'NoneType'>)
CREATE FUNCTION test_type_conversion_int4(x int4) RETURNS int4 AS $$ CREATE FUNCTION test_type_conversion_int4(x int4) RETURNS int4 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_int4(100); SELECT * FROM test_type_conversion_int4(100);
INFO: (100, <type 'int'>) INFO: (100, <class 'int'>)
test_type_conversion_int4 test_type_conversion_int4
--------------------------- ---------------------------
100 100
(1 row) (1 row)
SELECT * FROM test_type_conversion_int4(-100); SELECT * FROM test_type_conversion_int4(-100);
INFO: (-100, <type 'int'>) INFO: (-100, <class 'int'>)
test_type_conversion_int4 test_type_conversion_int4
--------------------------- ---------------------------
-100 -100
(1 row) (1 row)
SELECT * FROM test_type_conversion_int4(null); SELECT * FROM test_type_conversion_int4(null);
INFO: (None, <type 'NoneType'>) INFO: (None, <class 'NoneType'>)
test_type_conversion_int4 test_type_conversion_int4
--------------------------- ---------------------------
@ -162,30 +162,30 @@ INFO: (None, <type 'NoneType'>)
CREATE FUNCTION test_type_conversion_int8(x int8) RETURNS int8 AS $$ CREATE FUNCTION test_type_conversion_int8(x int8) RETURNS int8 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_int8(100); SELECT * FROM test_type_conversion_int8(100);
INFO: (100L, <type 'long'>) INFO: (100, <class 'int'>)
test_type_conversion_int8 test_type_conversion_int8
--------------------------- ---------------------------
100 100
(1 row) (1 row)
SELECT * FROM test_type_conversion_int8(-100); SELECT * FROM test_type_conversion_int8(-100);
INFO: (-100L, <type 'long'>) INFO: (-100, <class 'int'>)
test_type_conversion_int8 test_type_conversion_int8
--------------------------- ---------------------------
-100 -100
(1 row) (1 row)
SELECT * FROM test_type_conversion_int8(5000000000); SELECT * FROM test_type_conversion_int8(5000000000);
INFO: (5000000000L, <type 'long'>) INFO: (5000000000, <class 'int'>)
test_type_conversion_int8 test_type_conversion_int8
--------------------------- ---------------------------
5000000000 5000000000
(1 row) (1 row)
SELECT * FROM test_type_conversion_int8(null); SELECT * FROM test_type_conversion_int8(null);
INFO: (None, <type 'NoneType'>) INFO: (None, <class 'NoneType'>)
test_type_conversion_int8 test_type_conversion_int8
--------------------------- ---------------------------
@ -196,7 +196,7 @@ CREATE FUNCTION test_type_conversion_numeric(x numeric) RETURNS numeric AS $$
# between decimal and cdecimal # between decimal and cdecimal
plpy.info(str(x), x.__class__.__name__) plpy.info(str(x), x.__class__.__name__)
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_numeric(100); SELECT * FROM test_type_conversion_numeric(100);
INFO: ('100', 'Decimal') INFO: ('100', 'Decimal')
test_type_conversion_numeric test_type_conversion_numeric
@ -256,30 +256,30 @@ INFO: ('None', 'NoneType')
CREATE FUNCTION test_type_conversion_float4(x float4) RETURNS float4 AS $$ CREATE FUNCTION test_type_conversion_float4(x float4) RETURNS float4 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_float4(100); SELECT * FROM test_type_conversion_float4(100);
INFO: (100.0, <type 'float'>) INFO: (100.0, <class 'float'>)
test_type_conversion_float4 test_type_conversion_float4
----------------------------- -----------------------------
100 100
(1 row) (1 row)
SELECT * FROM test_type_conversion_float4(-100); SELECT * FROM test_type_conversion_float4(-100);
INFO: (-100.0, <type 'float'>) INFO: (-100.0, <class 'float'>)
test_type_conversion_float4 test_type_conversion_float4
----------------------------- -----------------------------
-100 -100
(1 row) (1 row)
SELECT * FROM test_type_conversion_float4(5000.5); SELECT * FROM test_type_conversion_float4(5000.5);
INFO: (5000.5, <type 'float'>) INFO: (5000.5, <class 'float'>)
test_type_conversion_float4 test_type_conversion_float4
----------------------------- -----------------------------
5000.5 5000.5
(1 row) (1 row)
SELECT * FROM test_type_conversion_float4(null); SELECT * FROM test_type_conversion_float4(null);
INFO: (None, <type 'NoneType'>) INFO: (None, <class 'NoneType'>)
test_type_conversion_float4 test_type_conversion_float4
----------------------------- -----------------------------
@ -288,37 +288,37 @@ INFO: (None, <type 'NoneType'>)
CREATE FUNCTION test_type_conversion_float8(x float8) RETURNS float8 AS $$ CREATE FUNCTION test_type_conversion_float8(x float8) RETURNS float8 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_float8(100); SELECT * FROM test_type_conversion_float8(100);
INFO: (100.0, <type 'float'>) INFO: (100.0, <class 'float'>)
test_type_conversion_float8 test_type_conversion_float8
----------------------------- -----------------------------
100 100
(1 row) (1 row)
SELECT * FROM test_type_conversion_float8(-100); SELECT * FROM test_type_conversion_float8(-100);
INFO: (-100.0, <type 'float'>) INFO: (-100.0, <class 'float'>)
test_type_conversion_float8 test_type_conversion_float8
----------------------------- -----------------------------
-100 -100
(1 row) (1 row)
SELECT * FROM test_type_conversion_float8(5000000000.5); SELECT * FROM test_type_conversion_float8(5000000000.5);
INFO: (5000000000.5, <type 'float'>) INFO: (5000000000.5, <class 'float'>)
test_type_conversion_float8 test_type_conversion_float8
----------------------------- -----------------------------
5000000000.5 5000000000.5
(1 row) (1 row)
SELECT * FROM test_type_conversion_float8(null); SELECT * FROM test_type_conversion_float8(null);
INFO: (None, <type 'NoneType'>) INFO: (None, <class 'NoneType'>)
test_type_conversion_float8 test_type_conversion_float8
----------------------------- -----------------------------
(1 row) (1 row)
SELECT * FROM test_type_conversion_float8(100100100.654321); SELECT * FROM test_type_conversion_float8(100100100.654321);
INFO: (100100100.654321, <type 'float'>) INFO: (100100100.654321, <class 'float'>)
test_type_conversion_float8 test_type_conversion_float8
----------------------------- -----------------------------
100100100.654321 100100100.654321
@ -327,23 +327,23 @@ INFO: (100100100.654321, <type 'float'>)
CREATE FUNCTION test_type_conversion_oid(x oid) RETURNS oid AS $$ CREATE FUNCTION test_type_conversion_oid(x oid) RETURNS oid AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_oid(100); SELECT * FROM test_type_conversion_oid(100);
INFO: (100L, <type 'long'>) INFO: (100, <class 'int'>)
test_type_conversion_oid test_type_conversion_oid
-------------------------- --------------------------
100 100
(1 row) (1 row)
SELECT * FROM test_type_conversion_oid(2147483649); SELECT * FROM test_type_conversion_oid(2147483649);
INFO: (2147483649L, <type 'long'>) INFO: (2147483649, <class 'int'>)
test_type_conversion_oid test_type_conversion_oid
-------------------------- --------------------------
2147483649 2147483649
(1 row) (1 row)
SELECT * FROM test_type_conversion_oid(null); SELECT * FROM test_type_conversion_oid(null);
INFO: (None, <type 'NoneType'>) INFO: (None, <class 'NoneType'>)
test_type_conversion_oid test_type_conversion_oid
-------------------------- --------------------------
@ -352,16 +352,16 @@ INFO: (None, <type 'NoneType'>)
CREATE FUNCTION test_type_conversion_text(x text) RETURNS text AS $$ CREATE FUNCTION test_type_conversion_text(x text) RETURNS text AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_text('hello world'); SELECT * FROM test_type_conversion_text('hello world');
INFO: ('hello world', <type 'str'>) INFO: ('hello world', <class 'str'>)
test_type_conversion_text test_type_conversion_text
--------------------------- ---------------------------
hello world hello world
(1 row) (1 row)
SELECT * FROM test_type_conversion_text(null); SELECT * FROM test_type_conversion_text(null);
INFO: (None, <type 'NoneType'>) INFO: (None, <class 'NoneType'>)
test_type_conversion_text test_type_conversion_text
--------------------------- ---------------------------
@ -370,23 +370,23 @@ INFO: (None, <type 'NoneType'>)
CREATE FUNCTION test_type_conversion_bytea(x bytea) RETURNS bytea AS $$ CREATE FUNCTION test_type_conversion_bytea(x bytea) RETURNS bytea AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_bytea('hello world'); SELECT * FROM test_type_conversion_bytea('hello world');
INFO: ('hello world', <type 'str'>) INFO: (b'hello world', <class 'bytes'>)
test_type_conversion_bytea test_type_conversion_bytea
---------------------------- ----------------------------
\x68656c6c6f20776f726c64 \x68656c6c6f20776f726c64
(1 row) (1 row)
SELECT * FROM test_type_conversion_bytea(E'null\\000byte'); SELECT * FROM test_type_conversion_bytea(E'null\\000byte');
INFO: ('null\x00byte', <type 'str'>) INFO: (b'null\x00byte', <class 'bytes'>)
test_type_conversion_bytea test_type_conversion_bytea
---------------------------- ----------------------------
\x6e756c6c0062797465 \x6e756c6c0062797465
(1 row) (1 row)
SELECT * FROM test_type_conversion_bytea(null); SELECT * FROM test_type_conversion_bytea(null);
INFO: (None, <type 'NoneType'>) INFO: (None, <class 'NoneType'>)
test_type_conversion_bytea test_type_conversion_bytea
---------------------------- ----------------------------
@ -395,14 +395,14 @@ INFO: (None, <type 'NoneType'>)
CREATE FUNCTION test_type_marshal() RETURNS bytea AS $$ CREATE FUNCTION test_type_marshal() RETURNS bytea AS $$
import marshal import marshal
return marshal.dumps('hello world') return marshal.dumps('hello world')
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_type_unmarshal(x bytea) RETURNS text AS $$ CREATE FUNCTION test_type_unmarshal(x bytea) RETURNS text AS $$
import marshal import marshal
try: try:
return marshal.loads(x) return marshal.loads(x)
except ValueError as e: except ValueError as e:
return 'FAILED: ' + str(e) return 'FAILED: ' + str(e)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT test_type_unmarshal(x) FROM test_type_marshal() x; SELECT test_type_unmarshal(x) FROM test_type_marshal() x;
test_type_unmarshal test_type_unmarshal
--------------------- ---------------------
@ -415,7 +415,7 @@ SELECT test_type_unmarshal(x) FROM test_type_marshal() x;
CREATE DOMAIN booltrue AS bool CHECK (VALUE IS TRUE OR VALUE IS NULL); CREATE DOMAIN booltrue AS bool CHECK (VALUE IS TRUE OR VALUE IS NULL);
CREATE FUNCTION test_type_conversion_booltrue(x booltrue, y bool) RETURNS booltrue AS $$ CREATE FUNCTION test_type_conversion_booltrue(x booltrue, y bool) RETURNS booltrue AS $$
return y return y
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_booltrue(true, true); SELECT * FROM test_type_conversion_booltrue(true, true);
test_type_conversion_booltrue test_type_conversion_booltrue
------------------------------- -------------------------------
@ -432,21 +432,21 @@ CREATE DOMAIN uint2 AS int2 CHECK (VALUE >= 0);
CREATE FUNCTION test_type_conversion_uint2(x uint2, y int) RETURNS uint2 AS $$ CREATE FUNCTION test_type_conversion_uint2(x uint2, y int) RETURNS uint2 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return y return y
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_uint2(100::uint2, 50); SELECT * FROM test_type_conversion_uint2(100::uint2, 50);
INFO: (100, <type 'int'>) INFO: (100, <class 'int'>)
test_type_conversion_uint2 test_type_conversion_uint2
---------------------------- ----------------------------
50 50
(1 row) (1 row)
SELECT * FROM test_type_conversion_uint2(100::uint2, -50); SELECT * FROM test_type_conversion_uint2(100::uint2, -50);
INFO: (100, <type 'int'>) INFO: (100, <class 'int'>)
ERROR: value for domain uint2 violates check constraint "uint2_check" ERROR: value for domain uint2 violates check constraint "uint2_check"
CONTEXT: while creating return value CONTEXT: while creating return value
PL/Python function "test_type_conversion_uint2" PL/Python function "test_type_conversion_uint2"
SELECT * FROM test_type_conversion_uint2(null, 1); SELECT * FROM test_type_conversion_uint2(null, 1);
INFO: (None, <type 'NoneType'>) INFO: (None, <class 'NoneType'>)
test_type_conversion_uint2 test_type_conversion_uint2
---------------------------- ----------------------------
1 1
@ -455,7 +455,7 @@ INFO: (None, <type 'NoneType'>)
CREATE DOMAIN nnint AS int CHECK (VALUE IS NOT NULL); CREATE DOMAIN nnint AS int CHECK (VALUE IS NOT NULL);
CREATE FUNCTION test_type_conversion_nnint(x nnint, y int) RETURNS nnint AS $$ CREATE FUNCTION test_type_conversion_nnint(x nnint, y int) RETURNS nnint AS $$
return y return y
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_nnint(10, 20); SELECT * FROM test_type_conversion_nnint(10, 20);
test_type_conversion_nnint test_type_conversion_nnint
---------------------------- ----------------------------
@ -472,9 +472,9 @@ CREATE DOMAIN bytea10 AS bytea CHECK (octet_length(VALUE) = 10 AND VALUE IS NOT
CREATE FUNCTION test_type_conversion_bytea10(x bytea10, y bytea) RETURNS bytea10 AS $$ CREATE FUNCTION test_type_conversion_bytea10(x bytea10, y bytea) RETURNS bytea10 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return y return y
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_bytea10('hello wold', 'hello wold'); SELECT * FROM test_type_conversion_bytea10('hello wold', 'hello wold');
INFO: ('hello wold', <type 'str'>) INFO: (b'hello wold', <class 'bytes'>)
test_type_conversion_bytea10 test_type_conversion_bytea10
------------------------------ ------------------------------
\x68656c6c6f20776f6c64 \x68656c6c6f20776f6c64
@ -483,14 +483,14 @@ INFO: ('hello wold', <type 'str'>)
SELECT * FROM test_type_conversion_bytea10('hello world', 'hello wold'); SELECT * FROM test_type_conversion_bytea10('hello world', 'hello wold');
ERROR: value for domain bytea10 violates check constraint "bytea10_check" ERROR: value for domain bytea10 violates check constraint "bytea10_check"
SELECT * FROM test_type_conversion_bytea10('hello word', 'hello world'); SELECT * FROM test_type_conversion_bytea10('hello word', 'hello world');
INFO: ('hello word', <type 'str'>) INFO: (b'hello word', <class 'bytes'>)
ERROR: value for domain bytea10 violates check constraint "bytea10_check" ERROR: value for domain bytea10 violates check constraint "bytea10_check"
CONTEXT: while creating return value CONTEXT: while creating return value
PL/Python function "test_type_conversion_bytea10" PL/Python function "test_type_conversion_bytea10"
SELECT * FROM test_type_conversion_bytea10(null, 'hello word'); SELECT * FROM test_type_conversion_bytea10(null, 'hello word');
ERROR: value for domain bytea10 violates check constraint "bytea10_check" ERROR: value for domain bytea10 violates check constraint "bytea10_check"
SELECT * FROM test_type_conversion_bytea10('hello word', null); SELECT * FROM test_type_conversion_bytea10('hello word', null);
INFO: ('hello word', <type 'str'>) INFO: (b'hello word', <class 'bytes'>)
ERROR: value for domain bytea10 violates check constraint "bytea10_check" ERROR: value for domain bytea10 violates check constraint "bytea10_check"
CONTEXT: while creating return value CONTEXT: while creating return value
PL/Python function "test_type_conversion_bytea10" PL/Python function "test_type_conversion_bytea10"
@ -500,58 +500,58 @@ PL/Python function "test_type_conversion_bytea10"
CREATE FUNCTION test_type_conversion_array_int4(x int4[]) RETURNS int4[] AS $$ CREATE FUNCTION test_type_conversion_array_int4(x int4[]) RETURNS int4[] AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_int4(ARRAY[0, 100]); SELECT * FROM test_type_conversion_array_int4(ARRAY[0, 100]);
INFO: ([0, 100], <type 'list'>) INFO: ([0, 100], <class 'list'>)
test_type_conversion_array_int4 test_type_conversion_array_int4
--------------------------------- ---------------------------------
{0,100} {0,100}
(1 row) (1 row)
SELECT * FROM test_type_conversion_array_int4(ARRAY[0,-100,55]); SELECT * FROM test_type_conversion_array_int4(ARRAY[0,-100,55]);
INFO: ([0, -100, 55], <type 'list'>) INFO: ([0, -100, 55], <class 'list'>)
test_type_conversion_array_int4 test_type_conversion_array_int4
--------------------------------- ---------------------------------
{0,-100,55} {0,-100,55}
(1 row) (1 row)
SELECT * FROM test_type_conversion_array_int4(ARRAY[NULL,1]); SELECT * FROM test_type_conversion_array_int4(ARRAY[NULL,1]);
INFO: ([None, 1], <type 'list'>) INFO: ([None, 1], <class 'list'>)
test_type_conversion_array_int4 test_type_conversion_array_int4
--------------------------------- ---------------------------------
{NULL,1} {NULL,1}
(1 row) (1 row)
SELECT * FROM test_type_conversion_array_int4(ARRAY[]::integer[]); SELECT * FROM test_type_conversion_array_int4(ARRAY[]::integer[]);
INFO: ([], <type 'list'>) INFO: ([], <class 'list'>)
test_type_conversion_array_int4 test_type_conversion_array_int4
--------------------------------- ---------------------------------
{} {}
(1 row) (1 row)
SELECT * FROM test_type_conversion_array_int4(NULL); SELECT * FROM test_type_conversion_array_int4(NULL);
INFO: (None, <type 'NoneType'>) INFO: (None, <class 'NoneType'>)
test_type_conversion_array_int4 test_type_conversion_array_int4
--------------------------------- ---------------------------------
(1 row) (1 row)
SELECT * FROM test_type_conversion_array_int4(ARRAY[[1,2,3],[4,5,6]]); SELECT * FROM test_type_conversion_array_int4(ARRAY[[1,2,3],[4,5,6]]);
INFO: ([[1, 2, 3], [4, 5, 6]], <type 'list'>) INFO: ([[1, 2, 3], [4, 5, 6]], <class 'list'>)
test_type_conversion_array_int4 test_type_conversion_array_int4
--------------------------------- ---------------------------------
{{1,2,3},{4,5,6}} {{1,2,3},{4,5,6}}
(1 row) (1 row)
SELECT * FROM test_type_conversion_array_int4(ARRAY[[[1,2,NULL],[NULL,5,6]],[[NULL,8,9],[10,11,12]]]); SELECT * FROM test_type_conversion_array_int4(ARRAY[[[1,2,NULL],[NULL,5,6]],[[NULL,8,9],[10,11,12]]]);
INFO: ([[[1, 2, None], [None, 5, 6]], [[None, 8, 9], [10, 11, 12]]], <type 'list'>) INFO: ([[[1, 2, None], [None, 5, 6]], [[None, 8, 9], [10, 11, 12]]], <class 'list'>)
test_type_conversion_array_int4 test_type_conversion_array_int4
--------------------------------------------------- ---------------------------------------------------
{{{1,2,NULL},{NULL,5,6}},{{NULL,8,9},{10,11,12}}} {{{1,2,NULL},{NULL,5,6}},{{NULL,8,9},{10,11,12}}}
(1 row) (1 row)
SELECT * FROM test_type_conversion_array_int4('[2:4]={1,2,3}'); SELECT * FROM test_type_conversion_array_int4('[2:4]={1,2,3}');
INFO: ([1, 2, 3], <type 'list'>) INFO: ([1, 2, 3], <class 'list'>)
test_type_conversion_array_int4 test_type_conversion_array_int4
--------------------------------- ---------------------------------
{1,2,3} {1,2,3}
@ -560,9 +560,9 @@ INFO: ([1, 2, 3], <type 'list'>)
CREATE FUNCTION test_type_conversion_array_int8(x int8[]) RETURNS int8[] AS $$ CREATE FUNCTION test_type_conversion_array_int8(x int8[]) RETURNS int8[] AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_int8(ARRAY[[[1,2,NULL],[NULL,5,6]],[[NULL,8,9],[10,11,12]]]::int8[]); SELECT * FROM test_type_conversion_array_int8(ARRAY[[[1,2,NULL],[NULL,5,6]],[[NULL,8,9],[10,11,12]]]::int8[]);
INFO: ([[[1L, 2L, None], [None, 5L, 6L]], [[None, 8L, 9L], [10L, 11L, 12L]]], <type 'list'>) INFO: ([[[1, 2, None], [None, 5, 6]], [[None, 8, 9], [10, 11, 12]]], <class 'list'>)
test_type_conversion_array_int8 test_type_conversion_array_int8
--------------------------------------------------- ---------------------------------------------------
{{{1,2,NULL},{NULL,5,6}},{{NULL,8,9},{10,11,12}}} {{{1,2,NULL},{NULL,5,6}},{{NULL,8,9},{10,11,12}}}
@ -571,10 +571,10 @@ INFO: ([[[1L, 2L, None], [None, 5L, 6L]], [[None, 8L, 9L], [10L, 11L, 12L]]], <
CREATE FUNCTION test_type_conversion_array_date(x date[]) RETURNS date[] AS $$ CREATE FUNCTION test_type_conversion_array_date(x date[]) RETURNS date[] AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_date(ARRAY[[['2016-09-21','2016-09-22',NULL],[NULL,'2016-10-21','2016-10-22']], SELECT * FROM test_type_conversion_array_date(ARRAY[[['2016-09-21','2016-09-22',NULL],[NULL,'2016-10-21','2016-10-22']],
[[NULL,'2016-11-21','2016-10-21'],['2015-09-21','2015-09-22','2014-09-21']]]::date[]); [[NULL,'2016-11-21','2016-10-21'],['2015-09-21','2015-09-22','2014-09-21']]]::date[]);
INFO: ([[['09-21-2016', '09-22-2016', None], [None, '10-21-2016', '10-22-2016']], [[None, '11-21-2016', '10-21-2016'], ['09-21-2015', '09-22-2015', '09-21-2014']]], <type 'list'>) INFO: ([[['09-21-2016', '09-22-2016', None], [None, '10-21-2016', '10-22-2016']], [[None, '11-21-2016', '10-21-2016'], ['09-21-2015', '09-22-2015', '09-21-2014']]], <class 'list'>)
test_type_conversion_array_date test_type_conversion_array_date
--------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------------------
{{{09-21-2016,09-22-2016,NULL},{NULL,10-21-2016,10-22-2016}},{{NULL,11-21-2016,10-21-2016},{09-21-2015,09-22-2015,09-21-2014}}} {{{09-21-2016,09-22-2016,NULL},{NULL,10-21-2016,10-22-2016}},{{NULL,11-21-2016,10-21-2016},{09-21-2015,09-22-2015,09-21-2014}}}
@ -583,12 +583,12 @@ INFO: ([[['09-21-2016', '09-22-2016', None], [None, '10-21-2016', '10-22-2016']
CREATE FUNCTION test_type_conversion_array_timestamp(x timestamp[]) RETURNS timestamp[] AS $$ CREATE FUNCTION test_type_conversion_array_timestamp(x timestamp[]) RETURNS timestamp[] AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_timestamp(ARRAY[[['2016-09-21 15:34:24.078792-04','2016-10-22 11:34:24.078795-04',NULL], SELECT * FROM test_type_conversion_array_timestamp(ARRAY[[['2016-09-21 15:34:24.078792-04','2016-10-22 11:34:24.078795-04',NULL],
[NULL,'2016-10-21 11:34:25.078792-04','2016-10-21 11:34:24.098792-04']], [NULL,'2016-10-21 11:34:25.078792-04','2016-10-21 11:34:24.098792-04']],
[[NULL,'2016-01-21 11:34:24.078792-04','2016-11-21 11:34:24.108792-04'], [[NULL,'2016-01-21 11:34:24.078792-04','2016-11-21 11:34:24.108792-04'],
['2015-09-21 11:34:24.079792-04','2014-09-21 11:34:24.078792-04','2013-09-21 11:34:24.078792-04']]]::timestamp[]); ['2015-09-21 11:34:24.079792-04','2014-09-21 11:34:24.078792-04','2013-09-21 11:34:24.078792-04']]]::timestamp[]);
INFO: ([[['Wed Sep 21 15:34:24.078792 2016', 'Sat Oct 22 11:34:24.078795 2016', None], [None, 'Fri Oct 21 11:34:25.078792 2016', 'Fri Oct 21 11:34:24.098792 2016']], [[None, 'Thu Jan 21 11:34:24.078792 2016', 'Mon Nov 21 11:34:24.108792 2016'], ['Mon Sep 21 11:34:24.079792 2015', 'Sun Sep 21 11:34:24.078792 2014', 'Sat Sep 21 11:34:24.078792 2013']]], <type 'list'>) INFO: ([[['Wed Sep 21 15:34:24.078792 2016', 'Sat Oct 22 11:34:24.078795 2016', None], [None, 'Fri Oct 21 11:34:25.078792 2016', 'Fri Oct 21 11:34:24.098792 2016']], [[None, 'Thu Jan 21 11:34:24.078792 2016', 'Mon Nov 21 11:34:24.108792 2016'], ['Mon Sep 21 11:34:24.079792 2015', 'Sun Sep 21 11:34:24.078792 2014', 'Sat Sep 21 11:34:24.078792 2013']]], <class 'list'>)
test_type_conversion_array_timestamp test_type_conversion_array_timestamp
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{"Wed Sep 21 15:34:24.078792 2016","Sat Oct 22 11:34:24.078795 2016",NULL},{NULL,"Fri Oct 21 11:34:25.078792 2016","Fri Oct 21 11:34:24.098792 2016"}},{{NULL,"Thu Jan 21 11:34:24.078792 2016","Mon Nov 21 11:34:24.108792 2016"},{"Mon Sep 21 11:34:24.079792 2015","Sun Sep 21 11:34:24.078792 2014","Sat Sep 21 11:34:24.078792 2013"}}} {{{"Wed Sep 21 15:34:24.078792 2016","Sat Oct 22 11:34:24.078795 2016",NULL},{NULL,"Fri Oct 21 11:34:25.078792 2016","Fri Oct 21 11:34:24.098792 2016"}},{{NULL,"Thu Jan 21 11:34:24.078792 2016","Mon Nov 21 11:34:24.108792 2016"},{"Mon Sep 21 11:34:24.079792 2015","Sun Sep 21 11:34:24.078792 2014","Sat Sep 21 11:34:24.078792 2013"}}}
@ -598,9 +598,9 @@ CREATE OR REPLACE FUNCTION pyreturnmultidemint4(h int4, i int4, j int4, k int4 )
m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)] m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)]
plpy.info(m, type(m)) plpy.info(m, type(m))
return m return m
$BODY$ LANGUAGE plpythonu; $BODY$ LANGUAGE plpython3u;
select pyreturnmultidemint4(8,5,3,2); select pyreturnmultidemint4(8,5,3,2);
INFO: ([[[[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]], [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]], [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]]], [[[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]], [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]], [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]]]], <type 'list'>) INFO: ([[[[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]], [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]], [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]]], [[[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]], [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]], [[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7]]]], <class 'list'>)
pyreturnmultidemint4 pyreturnmultidemint4
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7}},{{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7}},{{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7}}},{{{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7}},{{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7}},{{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7}}}} {{{{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7}},{{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7}},{{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7}}},{{{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7}},{{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7}},{{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7},{0,1,2,3,4,5,6,7}}}}
@ -610,9 +610,9 @@ CREATE OR REPLACE FUNCTION pyreturnmultidemint8(h int4, i int4, j int4, k int4 )
m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)] m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)]
plpy.info(m, type(m)) plpy.info(m, type(m))
return m return m
$BODY$ LANGUAGE plpythonu; $BODY$ LANGUAGE plpython3u;
select pyreturnmultidemint8(5,5,3,2); select pyreturnmultidemint8(5,5,3,2);
INFO: ([[[[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]], [[[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]]], <type 'list'>) INFO: ([[[[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]], [[[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]], [[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]]], <class 'list'>)
pyreturnmultidemint8 pyreturnmultidemint8
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4}},{{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4}},{{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4}}},{{{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4}},{{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4}},{{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4}}}} {{{{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4}},{{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4}},{{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4}}},{{{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4}},{{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4}},{{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4},{0,1,2,3,4}}}}
@ -622,9 +622,9 @@ CREATE OR REPLACE FUNCTION pyreturnmultidemfloat4(h int4, i int4, j int4, k int4
m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)] m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)]
plpy.info(m, type(m)) plpy.info(m, type(m))
return m return m
$BODY$ LANGUAGE plpythonu; $BODY$ LANGUAGE plpython3u;
select pyreturnmultidemfloat4(6,5,3,2); select pyreturnmultidemfloat4(6,5,3,2);
INFO: ([[[[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], [[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], [[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]]], [[[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], [[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], [[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]]]], <type 'list'>) INFO: ([[[[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], [[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], [[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]]], [[[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], [[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]], [[0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5], [0, 1, 2, 3, 4, 5]]]], <class 'list'>)
pyreturnmultidemfloat4 pyreturnmultidemfloat4
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5}},{{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5}},{{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5}}},{{{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5}},{{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5}},{{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5}}}} {{{{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5}},{{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5}},{{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5}}},{{{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5}},{{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5}},{{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5},{0,1,2,3,4,5}}}}
@ -634,9 +634,9 @@ CREATE OR REPLACE FUNCTION pyreturnmultidemfloat8(h int4, i int4, j int4, k int4
m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)] m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)]
plpy.info(m, type(m)) plpy.info(m, type(m))
return m return m
$BODY$ LANGUAGE plpythonu; $BODY$ LANGUAGE plpython3u;
select pyreturnmultidemfloat8(7,5,3,2); select pyreturnmultidemfloat8(7,5,3,2);
INFO: ([[[[0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]], [[0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]], [[0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]]], [[[0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]], [[0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]], [[0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]]]], <type 'list'>) INFO: ([[[[0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]], [[0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]], [[0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]]], [[[0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]], [[0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]], [[0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6]]]], <class 'list'>)
pyreturnmultidemfloat8 pyreturnmultidemfloat8
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{{{{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6}},{{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6}},{{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6}}},{{{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6}},{{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6}},{{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6}}}} {{{{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6}},{{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6}},{{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6}}},{{{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6}},{{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6}},{{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6},{0,1,2,3,4,5,6}}}}
@ -645,16 +645,16 @@ INFO: ([[[[0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6], [0, 1, 2, 3, 4, 5, 6],
CREATE FUNCTION test_type_conversion_array_text(x text[]) RETURNS text[] AS $$ CREATE FUNCTION test_type_conversion_array_text(x text[]) RETURNS text[] AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_text(ARRAY['foo', 'bar']); SELECT * FROM test_type_conversion_array_text(ARRAY['foo', 'bar']);
INFO: (['foo', 'bar'], <type 'list'>) INFO: (['foo', 'bar'], <class 'list'>)
test_type_conversion_array_text test_type_conversion_array_text
--------------------------------- ---------------------------------
{foo,bar} {foo,bar}
(1 row) (1 row)
SELECT * FROM test_type_conversion_array_text(ARRAY[['foo', 'bar'],['foo2', 'bar2']]); SELECT * FROM test_type_conversion_array_text(ARRAY[['foo', 'bar'],['foo2', 'bar2']]);
INFO: ([['foo', 'bar'], ['foo2', 'bar2']], <type 'list'>) INFO: ([['foo', 'bar'], ['foo2', 'bar2']], <class 'list'>)
test_type_conversion_array_text test_type_conversion_array_text
--------------------------------- ---------------------------------
{{foo,bar},{foo2,bar2}} {{foo,bar},{foo2,bar2}}
@ -663,9 +663,9 @@ INFO: ([['foo', 'bar'], ['foo2', 'bar2']], <type 'list'>)
CREATE FUNCTION test_type_conversion_array_bytea(x bytea[]) RETURNS bytea[] AS $$ CREATE FUNCTION test_type_conversion_array_bytea(x bytea[]) RETURNS bytea[] AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_bytea(ARRAY[E'\\xdeadbeef'::bytea, NULL]); SELECT * FROM test_type_conversion_array_bytea(ARRAY[E'\\xdeadbeef'::bytea, NULL]);
INFO: (['\xde\xad\xbe\xef', None], <type 'list'>) INFO: ([b'\xde\xad\xbe\xef', None], <class 'list'>)
test_type_conversion_array_bytea test_type_conversion_array_bytea
---------------------------------- ----------------------------------
{"\\xdeadbeef",NULL} {"\\xdeadbeef",NULL}
@ -673,7 +673,7 @@ INFO: (['\xde\xad\xbe\xef', None], <type 'list'>)
CREATE FUNCTION test_type_conversion_array_mixed1() RETURNS text[] AS $$ CREATE FUNCTION test_type_conversion_array_mixed1() RETURNS text[] AS $$
return [123, 'abc'] return [123, 'abc']
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_mixed1(); SELECT * FROM test_type_conversion_array_mixed1();
test_type_conversion_array_mixed1 test_type_conversion_array_mixed1
----------------------------------- -----------------------------------
@ -682,14 +682,14 @@ SELECT * FROM test_type_conversion_array_mixed1();
CREATE FUNCTION test_type_conversion_array_mixed2() RETURNS int[] AS $$ CREATE FUNCTION test_type_conversion_array_mixed2() RETURNS int[] AS $$
return [123, 'abc'] return [123, 'abc']
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_mixed2(); SELECT * FROM test_type_conversion_array_mixed2();
ERROR: invalid input syntax for type integer: "abc" ERROR: invalid input syntax for type integer: "abc"
CONTEXT: while creating return value CONTEXT: while creating return value
PL/Python function "test_type_conversion_array_mixed2" PL/Python function "test_type_conversion_array_mixed2"
CREATE FUNCTION test_type_conversion_mdarray_malformed() RETURNS int[] AS $$ CREATE FUNCTION test_type_conversion_mdarray_malformed() RETURNS int[] AS $$
return [[1,2,3],[4,5]] return [[1,2,3],[4,5]]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_mdarray_malformed(); SELECT * FROM test_type_conversion_mdarray_malformed();
ERROR: wrong length of inner sequence: has length 2, but 3 was expected ERROR: wrong length of inner sequence: has length 2, but 3 was expected
DETAIL: To construct a multidimensional array, the inner sequences must all have the same length. DETAIL: To construct a multidimensional array, the inner sequences must all have the same length.
@ -697,14 +697,14 @@ CONTEXT: while creating return value
PL/Python function "test_type_conversion_mdarray_malformed" PL/Python function "test_type_conversion_mdarray_malformed"
CREATE FUNCTION test_type_conversion_mdarray_toodeep() RETURNS int[] AS $$ CREATE FUNCTION test_type_conversion_mdarray_toodeep() RETURNS int[] AS $$
return [[[[[[[1]]]]]]] return [[[[[[[1]]]]]]]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_mdarray_toodeep(); SELECT * FROM test_type_conversion_mdarray_toodeep();
ERROR: number of array dimensions exceeds the maximum allowed (6) ERROR: number of array dimensions exceeds the maximum allowed (6)
CONTEXT: while creating return value CONTEXT: while creating return value
PL/Python function "test_type_conversion_mdarray_toodeep" PL/Python function "test_type_conversion_mdarray_toodeep"
CREATE FUNCTION test_type_conversion_array_record() RETURNS type_record[] AS $$ CREATE FUNCTION test_type_conversion_array_record() RETURNS type_record[] AS $$
return [{'first': 'one', 'second': 42}, {'first': 'two', 'second': 11}] return [{'first': 'one', 'second': 42}, {'first': 'two', 'second': 11}]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_record(); SELECT * FROM test_type_conversion_array_record();
test_type_conversion_array_record test_type_conversion_array_record
----------------------------------- -----------------------------------
@ -713,7 +713,7 @@ SELECT * FROM test_type_conversion_array_record();
CREATE FUNCTION test_type_conversion_array_string() RETURNS text[] AS $$ CREATE FUNCTION test_type_conversion_array_string() RETURNS text[] AS $$
return 'abc' return 'abc'
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_string(); SELECT * FROM test_type_conversion_array_string();
test_type_conversion_array_string test_type_conversion_array_string
----------------------------------- -----------------------------------
@ -722,7 +722,7 @@ SELECT * FROM test_type_conversion_array_string();
CREATE FUNCTION test_type_conversion_array_tuple() RETURNS text[] AS $$ CREATE FUNCTION test_type_conversion_array_tuple() RETURNS text[] AS $$
return ('abc', 'def') return ('abc', 'def')
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_tuple(); SELECT * FROM test_type_conversion_array_tuple();
test_type_conversion_array_tuple test_type_conversion_array_tuple
---------------------------------- ----------------------------------
@ -731,7 +731,7 @@ SELECT * FROM test_type_conversion_array_tuple();
CREATE FUNCTION test_type_conversion_array_error() RETURNS int[] AS $$ CREATE FUNCTION test_type_conversion_array_error() RETURNS int[] AS $$
return 5 return 5
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_error(); SELECT * FROM test_type_conversion_array_error();
ERROR: return value of function with array return type is not a Python sequence ERROR: return value of function with array return type is not a Python sequence
CONTEXT: while creating return value CONTEXT: while creating return value
@ -743,16 +743,16 @@ CREATE DOMAIN ordered_pair_domain AS integer[] CHECK (array_length(VALUE,1)=2 AN
CREATE FUNCTION test_type_conversion_array_domain(x ordered_pair_domain) RETURNS ordered_pair_domain AS $$ CREATE FUNCTION test_type_conversion_array_domain(x ordered_pair_domain) RETURNS ordered_pair_domain AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_domain(ARRAY[0, 100]::ordered_pair_domain); SELECT * FROM test_type_conversion_array_domain(ARRAY[0, 100]::ordered_pair_domain);
INFO: ([0, 100], <type 'list'>) INFO: ([0, 100], <class 'list'>)
test_type_conversion_array_domain test_type_conversion_array_domain
----------------------------------- -----------------------------------
{0,100} {0,100}
(1 row) (1 row)
SELECT * FROM test_type_conversion_array_domain(NULL::ordered_pair_domain); SELECT * FROM test_type_conversion_array_domain(NULL::ordered_pair_domain);
INFO: (None, <type 'NoneType'>) INFO: (None, <class 'NoneType'>)
test_type_conversion_array_domain test_type_conversion_array_domain
----------------------------------- -----------------------------------
@ -760,7 +760,7 @@ INFO: (None, <type 'NoneType'>)
CREATE FUNCTION test_type_conversion_array_domain_check_violation() RETURNS ordered_pair_domain AS $$ CREATE FUNCTION test_type_conversion_array_domain_check_violation() RETURNS ordered_pair_domain AS $$
return [2,1] return [2,1]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_domain_check_violation(); SELECT * FROM test_type_conversion_array_domain_check_violation();
ERROR: value for domain ordered_pair_domain violates check constraint "ordered_pair_domain_check" ERROR: value for domain ordered_pair_domain violates check constraint "ordered_pair_domain_check"
CONTEXT: while creating return value CONTEXT: while creating return value
@ -771,9 +771,9 @@ PL/Python function "test_type_conversion_array_domain_check_violation"
CREATE FUNCTION test_read_uint2_array(x uint2[]) RETURNS uint2 AS $$ CREATE FUNCTION test_read_uint2_array(x uint2[]) RETURNS uint2 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x[0] return x[0]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
select test_read_uint2_array(array[1::uint2]); select test_read_uint2_array(array[1::uint2]);
INFO: ([1], <type 'list'>) INFO: ([1], <class 'list'>)
test_read_uint2_array test_read_uint2_array
----------------------- -----------------------
1 1
@ -781,7 +781,7 @@ INFO: ([1], <type 'list'>)
CREATE FUNCTION test_build_uint2_array(x int2) RETURNS uint2[] AS $$ CREATE FUNCTION test_build_uint2_array(x int2) RETURNS uint2[] AS $$
return [x, x] return [x, x]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
select test_build_uint2_array(1::int2); select test_build_uint2_array(1::int2);
test_build_uint2_array test_build_uint2_array
------------------------ ------------------------
@ -800,7 +800,7 @@ PL/Python function "test_build_uint2_array"
CREATE FUNCTION test_type_conversion_domain_array(x integer[]) CREATE FUNCTION test_type_conversion_domain_array(x integer[])
RETURNS ordered_pair_domain[] AS $$ RETURNS ordered_pair_domain[] AS $$
return [x, x] return [x, x]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
select test_type_conversion_domain_array(array[2,4]); select test_type_conversion_domain_array(array[2,4]);
ERROR: return value of function with array return type is not a Python sequence ERROR: return value of function with array return type is not a Python sequence
CONTEXT: while creating return value CONTEXT: while creating return value
@ -813,9 +813,9 @@ CREATE FUNCTION test_type_conversion_domain_array2(x ordered_pair_domain)
RETURNS integer AS $$ RETURNS integer AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x[1] return x[1]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
select test_type_conversion_domain_array2(array[2,4]); select test_type_conversion_domain_array2(array[2,4]);
INFO: ([2, 4], <type 'list'>) INFO: ([2, 4], <class 'list'>)
test_type_conversion_domain_array2 test_type_conversion_domain_array2
------------------------------------ ------------------------------------
4 4
@ -827,9 +827,9 @@ CREATE FUNCTION test_type_conversion_array_domain_array(x ordered_pair_domain[])
RETURNS ordered_pair_domain AS $$ RETURNS ordered_pair_domain AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x[0] return x[0]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
select test_type_conversion_array_domain_array(array[array[2,4]::ordered_pair_domain]); select test_type_conversion_array_domain_array(array[array[2,4]::ordered_pair_domain]);
INFO: ([[2, 4]], <type 'list'>) INFO: ([[2, 4]], <class 'list'>)
test_type_conversion_array_domain_array test_type_conversion_array_domain_array
----------------------------------------- -----------------------------------------
{2,4} {2,4}
@ -846,7 +846,7 @@ CREATE TABLE employee (
INSERT INTO employee VALUES ('John', 100, 10), ('Mary', 200, 10); INSERT INTO employee VALUES ('John', 100, 10), ('Mary', 200, 10);
CREATE OR REPLACE FUNCTION test_composite_table_input(e employee) RETURNS integer AS $$ CREATE OR REPLACE FUNCTION test_composite_table_input(e employee) RETURNS integer AS $$
return e['basesalary'] + e['bonus'] return e['basesalary'] + e['bonus']
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT name, test_composite_table_input(employee.*) FROM employee; SELECT name, test_composite_table_input(employee.*) FROM employee;
name | test_composite_table_input name | test_composite_table_input
------+---------------------------- ------+----------------------------
@ -876,7 +876,7 @@ CREATE TYPE named_pair AS (
); );
CREATE OR REPLACE FUNCTION test_composite_type_input(p named_pair) RETURNS integer AS $$ CREATE OR REPLACE FUNCTION test_composite_type_input(p named_pair) RETURNS integer AS $$
return sum(p.values()) return sum(p.values())
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT test_composite_type_input(row(1, 2)); SELECT test_composite_type_input(row(1, 2));
test_composite_type_input test_composite_type_input
--------------------------- ---------------------------
@ -896,7 +896,7 @@ SELECT test_composite_type_input(row(1, 2));
CREATE TYPE nnint_container AS (f1 int, f2 nnint); CREATE TYPE nnint_container AS (f1 int, f2 nnint);
CREATE FUNCTION nnint_test(x int, y int) RETURNS nnint_container AS $$ CREATE FUNCTION nnint_test(x int, y int) RETURNS nnint_container AS $$
return {'f1': x, 'f2': y} return {'f1': x, 'f2': y}
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT nnint_test(null, 3); SELECT nnint_test(null, 3);
nnint_test nnint_test
------------ ------------
@ -913,7 +913,7 @@ PL/Python function "nnint_test"
CREATE DOMAIN ordered_named_pair AS named_pair_2 CHECK((VALUE).i <= (VALUE).j); CREATE DOMAIN ordered_named_pair AS named_pair_2 CHECK((VALUE).i <= (VALUE).j);
CREATE FUNCTION read_ordered_named_pair(p ordered_named_pair) RETURNS integer AS $$ CREATE FUNCTION read_ordered_named_pair(p ordered_named_pair) RETURNS integer AS $$
return p['i'] + p['j'] return p['i'] + p['j']
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT read_ordered_named_pair(row(1, 2)); SELECT read_ordered_named_pair(row(1, 2));
read_ordered_named_pair read_ordered_named_pair
------------------------- -------------------------
@ -924,7 +924,7 @@ SELECT read_ordered_named_pair(row(2, 1)); -- fail
ERROR: value for domain ordered_named_pair violates check constraint "ordered_named_pair_check" ERROR: value for domain ordered_named_pair violates check constraint "ordered_named_pair_check"
CREATE FUNCTION build_ordered_named_pair(i int, j int) RETURNS ordered_named_pair AS $$ CREATE FUNCTION build_ordered_named_pair(i int, j int) RETURNS ordered_named_pair AS $$
return {'i': i, 'j': j} return {'i': i, 'j': j}
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT build_ordered_named_pair(1,2); SELECT build_ordered_named_pair(1,2);
build_ordered_named_pair build_ordered_named_pair
-------------------------- --------------------------
@ -937,7 +937,7 @@ CONTEXT: while creating return value
PL/Python function "build_ordered_named_pair" PL/Python function "build_ordered_named_pair"
CREATE FUNCTION build_ordered_named_pairs(i int, j int) RETURNS ordered_named_pair[] AS $$ CREATE FUNCTION build_ordered_named_pairs(i int, j int) RETURNS ordered_named_pair[] AS $$
return [{'i': i, 'j': j}, {'i': i, 'j': j+1}] return [{'i': i, 'j': j}, {'i': i, 'j': j+1}]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT build_ordered_named_pairs(1,2); SELECT build_ordered_named_pairs(1,2);
build_ordered_named_pairs build_ordered_named_pairs
--------------------------- ---------------------------
@ -952,7 +952,7 @@ PL/Python function "build_ordered_named_pairs"
-- Prepared statements -- Prepared statements
-- --
CREATE OR REPLACE FUNCTION test_prep_bool_input() RETURNS int CREATE OR REPLACE FUNCTION test_prep_bool_input() RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plan = plpy.prepare("SELECT CASE WHEN $1 THEN 1 ELSE 0 END AS val", ['boolean']) plan = plpy.prepare("SELECT CASE WHEN $1 THEN 1 ELSE 0 END AS val", ['boolean'])
rv = plpy.execute(plan, ['fa'], 5) # 'fa' is true in Python rv = plpy.execute(plan, ['fa'], 5) # 'fa' is true in Python
@ -965,7 +965,7 @@ SELECT test_prep_bool_input(); -- 1
(1 row) (1 row)
CREATE OR REPLACE FUNCTION test_prep_bool_output() RETURNS bool CREATE OR REPLACE FUNCTION test_prep_bool_output() RETURNS bool
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plan = plpy.prepare("SELECT $1 = 1 AS val", ['int']) plan = plpy.prepare("SELECT $1 = 1 AS val", ['int'])
rv = plpy.execute(plan, [0], 5) rv = plpy.execute(plan, [0], 5)
@ -980,7 +980,7 @@ INFO: {'val': False}
(1 row) (1 row)
CREATE OR REPLACE FUNCTION test_prep_bytea_input(bb bytea) RETURNS int CREATE OR REPLACE FUNCTION test_prep_bytea_input(bb bytea) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plan = plpy.prepare("SELECT octet_length($1) AS val", ['bytea']) plan = plpy.prepare("SELECT octet_length($1) AS val", ['bytea'])
rv = plpy.execute(plan, [bb], 5) rv = plpy.execute(plan, [bb], 5)
@ -993,7 +993,7 @@ SELECT test_prep_bytea_input(E'a\\000b'); -- 3 (embedded null formerly truncated
(1 row) (1 row)
CREATE OR REPLACE FUNCTION test_prep_bytea_output() RETURNS bytea CREATE OR REPLACE FUNCTION test_prep_bytea_output() RETURNS bytea
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plan = plpy.prepare("SELECT decode('aa00bb', 'hex') AS val") plan = plpy.prepare("SELECT decode('aa00bb', 'hex') AS val")
rv = plpy.execute(plan, [], 5) rv = plpy.execute(plan, [], 5)
@ -1001,7 +1001,7 @@ plpy.info(rv[0])
return rv[0]['val'] return rv[0]['val']
$$; $$;
SELECT test_prep_bytea_output(); SELECT test_prep_bytea_output();
INFO: {'val': '\xaa\x00\xbb'} INFO: {'val': b'\xaa\x00\xbb'}
test_prep_bytea_output test_prep_bytea_output
------------------------ ------------------------
\xaa00bb \xaa00bb

File diff suppressed because it is too large Load Diff

View File

@ -11,24 +11,24 @@ CREATE TABLE unicode_test (
testvalue text NOT NULL testvalue text NOT NULL
); );
CREATE FUNCTION unicode_return() RETURNS text AS E' CREATE FUNCTION unicode_return() RETURNS text AS E'
return u"\\xA0" return "\\xA0"
' LANGUAGE plpythonu; ' LANGUAGE plpython3u;
CREATE FUNCTION unicode_trigger() RETURNS trigger AS E' CREATE FUNCTION unicode_trigger() RETURNS trigger AS E'
TD["new"]["testvalue"] = u"\\xA0" TD["new"]["testvalue"] = "\\xA0"
return "MODIFY" return "MODIFY"
' LANGUAGE plpythonu; ' LANGUAGE plpython3u;
CREATE TRIGGER unicode_test_bi BEFORE INSERT ON unicode_test CREATE TRIGGER unicode_test_bi BEFORE INSERT ON unicode_test
FOR EACH ROW EXECUTE PROCEDURE unicode_trigger(); FOR EACH ROW EXECUTE PROCEDURE unicode_trigger();
CREATE FUNCTION unicode_plan1() RETURNS text AS E' CREATE FUNCTION unicode_plan1() RETURNS text AS E'
plan = plpy.prepare("SELECT $1 AS testvalue", ["text"]) plan = plpy.prepare("SELECT $1 AS testvalue", ["text"])
rv = plpy.execute(plan, [u"\\xA0"], 1) rv = plpy.execute(plan, ["\\xA0"], 1)
return rv[0]["testvalue"] return rv[0]["testvalue"]
' LANGUAGE plpythonu; ' LANGUAGE plpython3u;
CREATE FUNCTION unicode_plan2() RETURNS text AS E' CREATE FUNCTION unicode_plan2() RETURNS text AS E'
plan = plpy.prepare("SELECT $1 || $2 AS testvalue", ["text", u"text"]) plan = plpy.prepare("SELECT $1 || $2 AS testvalue", ["text", "text"])
rv = plpy.execute(plan, ["foo", "bar"], 1) rv = plpy.execute(plan, ["foo", "bar"], 1)
return rv[0]["testvalue"] return rv[0]["testvalue"]
' LANGUAGE plpythonu; ' LANGUAGE plpython3u;
SELECT unicode_return(); SELECT unicode_return();
unicode_return unicode_return
---------------- ----------------

View File

@ -3,14 +3,14 @@
-- --
CREATE FUNCTION test_void_func1() RETURNS void AS $$ CREATE FUNCTION test_void_func1() RETURNS void AS $$
x = 10 x = 10
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
-- illegal: can't return non-None value in void-returning func -- illegal: can't return non-None value in void-returning func
CREATE FUNCTION test_void_func2() RETURNS void AS $$ CREATE FUNCTION test_void_func2() RETURNS void AS $$
return 10 return 10
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_return_none() RETURNS int AS $$ CREATE FUNCTION test_return_none() RETURNS int AS $$
None None
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
-- Tests for functions returning void -- Tests for functions returning void
SELECT test_void_func1(), test_void_func1() IS NULL AS "is null"; SELECT test_void_func1(), test_void_func1() IS NULL AS "is null";
test_void_func1 | is null test_void_func1 | is null

View File

@ -1,38 +0,0 @@
ifeq ($(python_majorversion),3)
# Adjust regression tests for Python 3 compatibility
#
# Mention those regression test files that need to be mangled in the
# variable REGRESS_PLPYTHON3_MANGLE. They will be copied to a
# subdirectory python3/ and have their Python syntax and other bits
# adjusted to work with Python 3.
# Note that the order of the tests needs to be preserved in this
# expression.
REGRESS := $(foreach test,$(REGRESS),$(if $(filter $(test),$(REGRESS_PLPYTHON3_MANGLE)),python3/$(test),$(test)))
.PHONY: pgregress-python3-mangle
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/<type 'exceptions\.\([[:alpha:]]*\)'>/<class '\1'>/g" \
-e "s/<type 'long'>/<class 'int'>/g" \
-e "s/\([0-9][0-9]*\)L/\1/g" \
-e 's/\([ [{]\)u"/\1"/g' \
-e "s/\([ [{]\)u'/\1'/g" \
-e "s/def next/def __next__/g" \
-e "s/LANGUAGE plpythonu/LANGUAGE plpython3u/g" \
-e "s/LANGUAGE plpython2u/LANGUAGE plpython3u/g" \
-e "s/EXTENSION plpythonu/EXTENSION plpython3u/g" \
-e "s/EXTENSION plpython2u/EXTENSION plpython3u/g" \
-e "s/EXTENSION \([^ ]*\)_plpythonu/EXTENSION \1_plpython3u/g" \
-e "s/EXTENSION \([^ ]*\)_plpython2u/EXTENSION \1_plpython3u/g" \
-e 's/installing required extension "plpython2u"/installing required extension "plpython3u"/g' \
$$file >`echo $$file | sed 's,^.*/\([^/][^/]*/\)\([^/][^/]*\)$$,\1python3/\2,'` || exit; \
done
check installcheck: pgregress-python3-mangle
pg_regress_clean_files += sql/python3/ expected/python3/ results/python3/
endif # Python 3

View File

@ -3,7 +3,7 @@
-- --
CREATE PROCEDURE test_proc1() CREATE PROCEDURE test_proc1()
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
pass pass
$$; $$;
@ -13,7 +13,7 @@ CALL test_proc1();
-- error: can't return non-None -- error: can't return non-None
CREATE PROCEDURE test_proc2() CREATE PROCEDURE test_proc2()
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
return 5 return 5
$$; $$;
@ -24,7 +24,7 @@ CALL test_proc2();
CREATE TABLE test1 (a int); CREATE TABLE test1 (a int);
CREATE PROCEDURE test_proc3(x int) CREATE PROCEDURE test_proc3(x int)
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plpy.execute("INSERT INTO test1 VALUES (%s)" % x) plpy.execute("INSERT INTO test1 VALUES (%s)" % x)
$$; $$;
@ -37,7 +37,7 @@ SELECT * FROM test1;
-- output arguments -- output arguments
CREATE PROCEDURE test_proc5(INOUT a text) CREATE PROCEDURE test_proc5(INOUT a text)
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
return [a + '+' + a] return [a + '+' + a]
$$; $$;
@ -46,7 +46,7 @@ CALL test_proc5('abc');
CREATE PROCEDURE test_proc6(a int, INOUT b int, INOUT c int) CREATE PROCEDURE test_proc6(a int, INOUT b int, INOUT c int)
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
return (b * a, c * a) return (b * a, c * a)
$$; $$;
@ -57,7 +57,7 @@ CALL test_proc6(2, 3, 4);
-- OUT parameters -- OUT parameters
CREATE PROCEDURE test_proc9(IN a int, OUT b int) CREATE PROCEDURE test_proc9(IN a int, OUT b int)
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plpy.notice("a: %s" % (a)) plpy.notice("a: %s" % (a))
return (a * 2,) return (a * 2,)

View File

@ -1,6 +1,6 @@
CREATE FUNCTION multiout_simple(OUT i integer, OUT j integer) AS $$ CREATE FUNCTION multiout_simple(OUT i integer, OUT j integer) AS $$
return (1, 2) return (1, 2)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT multiout_simple(); SELECT multiout_simple();
SELECT * FROM multiout_simple(); SELECT * FROM multiout_simple();
@ -9,7 +9,7 @@ SELECT (multiout_simple()).j + 3;
CREATE FUNCTION multiout_simple_setof(n integer = 1, OUT integer, OUT integer) RETURNS SETOF record AS $$ CREATE FUNCTION multiout_simple_setof(n integer = 1, OUT integer, OUT integer) RETURNS SETOF record AS $$
return [(1, 2)] * n return [(1, 2)] * n
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT multiout_simple_setof(); SELECT multiout_simple_setof();
SELECT * FROM multiout_simple_setof(); SELECT * FROM multiout_simple_setof();
@ -34,7 +34,7 @@ elif typ == 'obj':
return type_record return type_record
elif typ == 'str': elif typ == 'str':
return "('%s',%r)" % (first, second) return "('%s',%r)" % (first, second)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM multiout_record_as('dict', 'foo', 1, 'f'); SELECT * FROM multiout_record_as('dict', 'foo', 1, 'f');
SELECT multiout_record_as('dict', 'foo', 1, 'f'); SELECT multiout_record_as('dict', 'foo', 1, 'f');
@ -77,7 +77,7 @@ for i in range(n):
power = 2 ** i power = 2 ** i
length = plpy.execute("select length('%d')" % power)[0]['length'] length = plpy.execute("select length('%d')" % power)[0]['length']
yield power, length yield power, length
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM multiout_setof(3); SELECT * FROM multiout_setof(3);
SELECT multiout_setof(5); SELECT multiout_setof(5);
@ -86,7 +86,7 @@ CREATE FUNCTION multiout_return_table() RETURNS TABLE (x integer, y text) AS $$
return [{'x': 4, 'y' :'four'}, return [{'x': 4, 'y' :'four'},
{'x': 7, 'y' :'seven'}, {'x': 7, 'y' :'seven'},
{'x': 0, 'y' :'zero'}] {'x': 0, 'y' :'zero'}]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM multiout_return_table(); SELECT * FROM multiout_return_table();
@ -94,18 +94,18 @@ CREATE FUNCTION multiout_array(OUT integer[], OUT text) RETURNS SETOF record AS
yield [[1], 'a'] yield [[1], 'a']
yield [[1,2], 'b'] yield [[1,2], 'b']
yield [[1,2,3], None] yield [[1,2,3], None]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM multiout_array(); SELECT * FROM multiout_array();
CREATE FUNCTION singleout_composite(OUT type_record) AS $$ CREATE FUNCTION singleout_composite(OUT type_record) AS $$
return {'first': 1, 'second': 2} return {'first': 1, 'second': 2}
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION multiout_composite(OUT type_record) RETURNS SETOF type_record AS $$ CREATE FUNCTION multiout_composite(OUT type_record) RETURNS SETOF type_record AS $$
return [{'first': 1, 'second': 2}, return [{'first': 1, 'second': 2},
{'first': 3, 'second': 4 }] {'first': 3, 'second': 4 }]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM singleout_composite(); SELECT * FROM singleout_composite();
SELECT * FROM multiout_composite(); SELECT * FROM multiout_composite();
@ -113,7 +113,7 @@ SELECT * FROM multiout_composite();
-- composite OUT parameters in functions returning RECORD not supported yet -- composite OUT parameters in functions returning RECORD not supported yet
CREATE FUNCTION multiout_composite(INOUT n integer, OUT type_record) AS $$ CREATE FUNCTION multiout_composite(INOUT n integer, OUT type_record) AS $$
return (n, (n * 2, n * 3)) return (n, (n * 2, n * 3))
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION multiout_table_type_setof(typ text, returnnull boolean, INOUT n integer, OUT table_record) RETURNS SETOF record AS $$ CREATE FUNCTION multiout_table_type_setof(typ text, returnnull boolean, INOUT n integer, OUT table_record) RETURNS SETOF record AS $$
if returnnull: if returnnull:
@ -132,7 +132,7 @@ elif typ == 'str':
d = "(%r,%r)" % (n * 2, n * 3) d = "(%r,%r)" % (n * 2, n * 3)
for i in range(n): for i in range(n):
yield (i, d) yield (i, d)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM multiout_composite(2); SELECT * FROM multiout_composite(2);
SELECT * FROM multiout_table_type_setof('dict', 'f', 3); SELECT * FROM multiout_table_type_setof('dict', 'f', 3);
@ -157,7 +157,7 @@ CREATE TABLE changing (
CREATE FUNCTION changing_test(OUT n integer, OUT changing) RETURNS SETOF record AS $$ CREATE FUNCTION changing_test(OUT n integer, OUT changing) RETURNS SETOF record AS $$
return [(1, {'i': 1, 'j': 2}), return [(1, {'i': 1, 'j': 2}),
(1, (3, 4))] (1, (3, 4))]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM changing_test(); SELECT * FROM changing_test();
ALTER TABLE changing DROP COLUMN j; ALTER TABLE changing DROP COLUMN j;
@ -178,14 +178,14 @@ yield {'tab': [('first', 1), ('second', 2)],
yield {'tab': [('first', 1), ('second', 2)], yield {'tab': [('first', 1), ('second', 2)],
'typ': [{'first': 'third', 'second': 3}, 'typ': [{'first': 'third', 'second': 3},
{'first': 'fourth', 'second': 4}]} {'first': 'fourth', 'second': 4}]}
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM composite_types_table(); SELECT * FROM composite_types_table();
-- check what happens if the output record descriptor changes -- check what happens if the output record descriptor changes
CREATE FUNCTION return_record(t text) RETURNS record AS $$ CREATE FUNCTION return_record(t text) RETURNS record AS $$
return {'t': t, 'val': 10} return {'t': t, 'val': 10}
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM return_record('abc') AS r(t text, val integer); SELECT * FROM return_record('abc') AS r(t text, val integer);
SELECT * FROM return_record('abc') AS r(t text, val bigint); SELECT * FROM return_record('abc') AS r(t text, val bigint);
@ -196,7 +196,7 @@ SELECT * FROM return_record('999') AS r(val text, t integer);
CREATE FUNCTION return_record_2(t text) RETURNS record AS $$ CREATE FUNCTION return_record_2(t text) RETURNS record AS $$
return {'v1':1,'v2':2,t:3} return {'v1':1,'v2':2,t:3}
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM return_record_2('v3') AS (v3 int, v2 int, v1 int); SELECT * FROM return_record_2('v3') AS (v3 int, v2 int, v1 int);
SELECT * FROM return_record_2('v3') AS (v2 int, v3 int, v1 int); SELECT * FROM return_record_2('v3') AS (v2 int, v3 int, v1 int);
@ -211,7 +211,7 @@ SELECT * FROM return_record_2('v3') AS (v1 int, v2 int, v3 int);
-- multi-dimensional array of composite types. -- multi-dimensional array of composite types.
CREATE FUNCTION composite_type_as_list() RETURNS type_record[] AS $$ CREATE FUNCTION composite_type_as_list() RETURNS type_record[] AS $$
return [[('first', 1), ('second', 1)], [('first', 2), ('second', 2)], [('first', 3), ('second', 3)]]; return [[('first', 1), ('second', 1)], [('first', 2), ('second', 2)], [('first', 3), ('second', 3)]];
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM composite_type_as_list(); SELECT * FROM composite_type_as_list();
-- Starting with PostgreSQL 10, a composite type in an array cannot be -- Starting with PostgreSQL 10, a composite type in an array cannot be
@ -220,5 +220,5 @@ SELECT * FROM composite_type_as_list();
-- on the issue. -- on the issue.
CREATE FUNCTION composite_type_as_list_broken() RETURNS type_record[] AS $$ CREATE FUNCTION composite_type_as_list_broken() RETURNS type_record[] AS $$
return [['first', 1]]; return [['first', 1]];
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM composite_type_as_list_broken(); SELECT * FROM composite_type_as_list_broken();

View File

@ -1,5 +1,3 @@
DO $$ plpy.notice("This is plpythonu.") $$ LANGUAGE plpythonu; DO $$ plpy.notice("This is plpython3u.") $$ LANGUAGE plpython3u;
DO $$ plpy.notice("This is plpython2u.") $$ LANGUAGE plpython2u; DO $$ raise Exception("error test") $$ LANGUAGE plpython3u;
DO $$ raise Exception("error test") $$ LANGUAGE plpythonu;

View File

@ -3,6 +3,4 @@
-- --
SET client_min_messages = WARNING; SET client_min_messages = WARNING;
DROP EXTENSION plpythonu CASCADE; DROP EXTENSION plpython3u CASCADE;
DROP EXTENSION IF EXISTS plpython2u CASCADE;

View File

@ -17,28 +17,28 @@ plpy.info('This is message text.',
plpy.notice('notice', detail='some detail') plpy.notice('notice', detail='some detail')
plpy.warning('warning', detail='some detail') plpy.warning('warning', detail='some detail')
plpy.error('stop on error', detail='some detail', hint='some hint') plpy.error('stop on error', detail='some detail', hint='some hint')
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT elog_test(); SELECT elog_test();
DO $$ plpy.info('other types', detail=(10, 20)) $$ LANGUAGE plpythonu; DO $$ plpy.info('other types', detail=(10, 20)) $$ LANGUAGE plpython3u;
DO $$ DO $$
import time; import time;
from datetime import date from datetime import date
plpy.info('other types', detail=date(2016, 2, 26)) plpy.info('other types', detail=date(2016, 2, 26))
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
DO $$ DO $$
basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana'] basket = ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
plpy.info('other types', detail=basket) plpy.info('other types', detail=basket)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
-- should fail -- should fail
DO $$ plpy.info('wrong sqlstate', sqlstate='54444A') $$ LANGUAGE plpythonu; DO $$ plpy.info('wrong sqlstate', sqlstate='54444A') $$ LANGUAGE plpython3u;
DO $$ plpy.info('unsupported argument', blabla='fooboo') $$ LANGUAGE plpythonu; DO $$ plpy.info('unsupported argument', blabla='fooboo') $$ LANGUAGE plpython3u;
DO $$ plpy.info('first message', message='second message') $$ LANGUAGE plpythonu; DO $$ plpy.info('first message', message='second message') $$ LANGUAGE plpython3u;
DO $$ plpy.info('first message', 'second message', message='third message') $$ LANGUAGE plpythonu; DO $$ plpy.info('first message', 'second message', message='third message') $$ LANGUAGE plpython3u;
-- raise exception in python, handle exception in plgsql -- raise exception in python, handle exception in plgsql
CREATE OR REPLACE FUNCTION raise_exception(_message text, _detail text DEFAULT NULL, _hint text DEFAULT NULL, CREATE OR REPLACE FUNCTION raise_exception(_message text, _detail text DEFAULT NULL, _hint text DEFAULT NULL,
@ -57,7 +57,7 @@ kwargs = {
} }
# ignore None values # ignore None values
plpy.error(**dict((k, v) for k, v in iter(kwargs.items()) if v)) plpy.error(**dict((k, v) for k, v in iter(kwargs.items()) if v))
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT raise_exception('hello', 'world'); SELECT raise_exception('hello', 'world');
SELECT raise_exception('message text', 'detail text', _sqlstate => 'YY333'); SELECT raise_exception('message text', 'detail text', _sqlstate => 'YY333');
@ -118,17 +118,13 @@ BEGIN
END; END;
$$; $$;
-- The displayed context is different between Python2 and Python3,
-- but that's not important for this test.
\set SHOW_CONTEXT never
DO $$ DO $$
try: try:
plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table_name => 'users_tab', _datatype_name => 'user_type')") plpy.execute("select raise_exception(_message => 'my message', _sqlstate => 'XX987', _hint => 'some hint', _table_name => 'users_tab', _datatype_name => 'user_type')")
except Exception as e: except Exception as e:
plpy.info(e.spidata) plpy.info(e.spidata)
raise e raise e
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
DO $$ DO $$
try: try:
@ -136,4 +132,4 @@ try:
except Exception as 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)) plpy.info('sqlstate: %s, hint: %s, table_name: %s, datatype_name: %s' % (e.sqlstate, e.hint, e.table_name, e.datatype_name))
raise e raise e
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;

View File

@ -7,7 +7,7 @@
CREATE FUNCTION python_syntax_error() RETURNS text CREATE FUNCTION python_syntax_error() RETURNS text
AS AS
'.syntaxerror' '.syntaxerror'
LANGUAGE plpythonu; LANGUAGE plpython3u;
/* With check_function_bodies = false the function should get defined /* With check_function_bodies = false the function should get defined
* and the error reported when called * and the error reported when called
@ -17,7 +17,7 @@ SET check_function_bodies = false;
CREATE FUNCTION python_syntax_error() RETURNS text CREATE FUNCTION python_syntax_error() RETURNS text
AS AS
'.syntaxerror' '.syntaxerror'
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT python_syntax_error(); SELECT python_syntax_error();
/* Run the function twice to check if the hashtable entry gets cleaned up */ /* Run the function twice to check if the hashtable entry gets cleaned up */
@ -30,7 +30,7 @@ RESET check_function_bodies;
CREATE FUNCTION sql_syntax_error() RETURNS text CREATE FUNCTION sql_syntax_error() RETURNS text
AS AS
'plpy.execute("syntax error")' 'plpy.execute("syntax error")'
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT sql_syntax_error(); SELECT sql_syntax_error();
@ -40,7 +40,7 @@ SELECT sql_syntax_error();
CREATE FUNCTION exception_index_invalid(text) RETURNS text CREATE FUNCTION exception_index_invalid(text) RETURNS text
AS AS
'return args[1]' 'return args[1]'
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT exception_index_invalid('test'); SELECT exception_index_invalid('test');
@ -51,7 +51,7 @@ CREATE FUNCTION exception_index_invalid_nested() RETURNS text
AS AS
'rv = plpy.execute("SELECT test5(''foo'')") 'rv = plpy.execute("SELECT test5(''foo'')")
return rv[0]' return rv[0]'
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT exception_index_invalid_nested(); SELECT exception_index_invalid_nested();
@ -68,7 +68,7 @@ if len(rv):
return rv[0]["fname"] return rv[0]["fname"]
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT invalid_type_uncaught('rick'); SELECT invalid_type_uncaught('rick');
@ -90,7 +90,7 @@ if len(rv):
return rv[0]["fname"] return rv[0]["fname"]
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT invalid_type_caught('rick'); SELECT invalid_type_caught('rick');
@ -111,7 +111,7 @@ if len(rv):
return rv[0]["fname"] return rv[0]["fname"]
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT invalid_type_reraised('rick'); SELECT invalid_type_reraised('rick');
@ -127,7 +127,7 @@ if len(rv):
return rv[0]["fname"] return rv[0]["fname"]
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT valid_type('rick'); SELECT valid_type('rick');
@ -147,7 +147,7 @@ def fun3():
fun3() fun3()
return "not reached" return "not reached"
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT nested_error(); SELECT nested_error();
@ -167,7 +167,7 @@ def fun3():
fun3() fun3()
return "not reached" return "not reached"
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT nested_error_raise(); SELECT nested_error_raise();
@ -187,7 +187,7 @@ def fun3():
fun3() fun3()
return "you''ve been warned" return "you''ve been warned"
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT nested_warning(); SELECT nested_warning();
@ -196,7 +196,7 @@ SELECT nested_warning();
CREATE FUNCTION toplevel_attribute_error() RETURNS void AS CREATE FUNCTION toplevel_attribute_error() RETURNS void AS
$$ $$
plpy.nonexistent plpy.nonexistent
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT toplevel_attribute_error(); SELECT toplevel_attribute_error();
@ -213,7 +213,7 @@ def third():
plpy.execute("select sql_error()") plpy.execute("select sql_error()")
first() first()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION sql_error() RETURNS void AS $$ CREATE OR REPLACE FUNCTION sql_error() RETURNS void AS $$
begin begin
@ -229,7 +229,7 @@ $$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION sql_from_python_error() RETURNS void AS $$ CREATE OR REPLACE FUNCTION sql_from_python_error() RETURNS void AS $$
plpy.execute("select sql_error()") plpy.execute("select sql_error()")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT python_traceback(); SELECT python_traceback();
SELECT sql_error(); SELECT sql_error();
@ -251,7 +251,7 @@ except spiexceptions.NotNullViolation as e:
plpy.notice("Violated the NOT NULL constraint, sqlstate %s" % e.sqlstate) plpy.notice("Violated the NOT NULL constraint, sqlstate %s" % e.sqlstate)
except spiexceptions.UniqueViolation as e: except spiexceptions.UniqueViolation as e:
plpy.notice("Violated the UNIQUE constraint, sqlstate %s" % e.sqlstate) plpy.notice("Violated the UNIQUE constraint, sqlstate %s" % e.sqlstate)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT specific_exception(2); SELECT specific_exception(2);
SELECT specific_exception(NULL); SELECT specific_exception(NULL);
@ -262,7 +262,7 @@ SELECT specific_exception(2);
CREATE FUNCTION python_unique_violation() RETURNS void AS $$ CREATE FUNCTION python_unique_violation() RETURNS void AS $$
plpy.execute("insert into specific values (1)") plpy.execute("insert into specific values (1)")
plpy.execute("insert into specific values (1)") plpy.execute("insert into specific values (1)")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION catch_python_unique_violation() RETURNS text AS $$ CREATE FUNCTION catch_python_unique_violation() RETURNS text AS $$
begin begin
@ -283,7 +283,7 @@ CREATE FUNCTION manual_subxact() RETURNS void AS $$
plpy.execute("savepoint save") plpy.execute("savepoint save")
plpy.execute("create table foo(x integer)") plpy.execute("create table foo(x integer)")
plpy.execute("rollback to save") plpy.execute("rollback to save")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT manual_subxact(); SELECT manual_subxact();
@ -295,7 +295,7 @@ rollback = plpy.prepare("rollback to save")
plpy.execute(save) plpy.execute(save)
plpy.execute("create table foo(x integer)") plpy.execute("create table foo(x integer)")
plpy.execute(rollback) plpy.execute(rollback)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT manual_subxact_prepared(); SELECT manual_subxact_prepared();
@ -303,7 +303,7 @@ SELECT manual_subxact_prepared();
*/ */
CREATE FUNCTION plpy_raise_spiexception() RETURNS void AS $$ CREATE FUNCTION plpy_raise_spiexception() RETURNS void AS $$
raise plpy.spiexceptions.DivisionByZero() raise plpy.spiexceptions.DivisionByZero()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
DO $$ DO $$
BEGIN BEGIN
@ -319,7 +319,7 @@ CREATE FUNCTION plpy_raise_spiexception_override() RETURNS void AS $$
exc = plpy.spiexceptions.DivisionByZero() exc = plpy.spiexceptions.DivisionByZero()
exc.sqlstate = 'SILLY' exc.sqlstate = 'SILLY'
raise exc raise exc
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
DO $$ DO $$
BEGIN BEGIN
@ -332,14 +332,14 @@ $$ LANGUAGE plpgsql;
/* test the context stack trace for nested execution levels /* test the context stack trace for nested execution levels
*/ */
CREATE FUNCTION notice_innerfunc() RETURNS int AS $$ CREATE FUNCTION notice_innerfunc() RETURNS int AS $$
plpy.execute("DO LANGUAGE plpythonu $x$ plpy.notice('inside DO') $x$") plpy.execute("DO LANGUAGE plpython3u $x$ plpy.notice('inside DO') $x$")
return 1 return 1
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION notice_outerfunc() RETURNS int AS $$ CREATE FUNCTION notice_outerfunc() RETURNS int AS $$
plpy.execute("SELECT notice_innerfunc()") plpy.execute("SELECT notice_innerfunc()")
return 1 return 1
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
\set SHOW_CONTEXT always \set SHOW_CONTEXT always

View File

@ -9,7 +9,7 @@ CREATE FUNCTION global_test_one() returns text
if "global_test" not in GD: if "global_test" not in GD:
GD["global_test"] = "set by global_test_one" GD["global_test"] = "set by global_test_one"
return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]' return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION global_test_two() returns text CREATE FUNCTION global_test_two() returns text
AS AS
@ -18,7 +18,7 @@ CREATE FUNCTION global_test_two() returns text
if "global_test" not in GD: if "global_test" not in GD:
GD["global_test"] = "set by global_test_two" GD["global_test"] = "set by global_test_two"
return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]' return "SD: " + SD["global_test"] + ", GD: " + GD["global_test"]'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION static_test() returns int4 CREATE FUNCTION static_test() returns int4
@ -29,7 +29,7 @@ else:
SD["call"] = 1 SD["call"] = 1
return SD["call"] return SD["call"]
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT static_test(); SELECT static_test();

View File

@ -7,7 +7,7 @@ CREATE FUNCTION import_fail() returns text
except ImportError: except ImportError:
return "failed as expected" return "failed as expected"
return "succeeded, that wasn''t supposed to happen"' return "succeeded, that wasn''t supposed to happen"'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION import_succeed() returns text CREATE FUNCTION import_succeed() returns text
@ -28,7 +28,7 @@ except Exception as ex:
plpy.notice("import failed -- %s" % str(ex)) plpy.notice("import failed -- %s" % str(ex))
return "failed, that wasn''t supposed to happen" return "failed, that wasn''t supposed to happen"
return "succeeded, as expected"' return "succeeded, as expected"'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION import_test_one(p text) RETURNS text CREATE FUNCTION import_test_one(p text) RETURNS text
AS AS
@ -39,7 +39,7 @@ except ImportError:
import sha import sha
digest = sha.new(p) digest = sha.new(p)
return digest.hexdigest()' return digest.hexdigest()'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION import_test_two(u users) RETURNS text CREATE FUNCTION import_test_two(u users) RETURNS text
AS AS
@ -51,7 +51,7 @@ except ImportError:
import sha import sha
digest = sha.new(plain); digest = sha.new(plain);
return "sha hash of " + plain + " is " + digest.hexdigest()' return "sha hash of " + plain + " is " + digest.hexdigest()'
LANGUAGE plpythonu; LANGUAGE plpython3u;
-- import python modules -- import python modules

View File

@ -4,15 +4,15 @@
CREATE OR REPLACE FUNCTION newline_lf() RETURNS integer AS CREATE OR REPLACE FUNCTION newline_lf() RETURNS integer AS
E'x = 100\ny = 23\nreturn x + y\n' E'x = 100\ny = 23\nreturn x + y\n'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION newline_cr() RETURNS integer AS CREATE OR REPLACE FUNCTION newline_cr() RETURNS integer AS
E'x = 100\ry = 23\rreturn x + y\r' E'x = 100\ry = 23\rreturn x + y\r'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE OR REPLACE FUNCTION newline_crlf() RETURNS integer AS CREATE OR REPLACE FUNCTION newline_crlf() RETURNS integer AS
E'x = 100\r\ny = 23\r\nreturn x + y\r\n' E'x = 100\r\ny = 23\r\nreturn x + y\r\n'
LANGUAGE plpythonu; LANGUAGE plpython3u;
SELECT newline_lf(); SELECT newline_lf();

View File

@ -4,13 +4,13 @@
CREATE FUNCTION test_param_names0(integer, integer) RETURNS int AS $$ CREATE FUNCTION test_param_names0(integer, integer) RETURNS int AS $$
return args[0] + args[1] return args[0] + args[1]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_param_names1(a0 integer, a1 text) RETURNS boolean AS $$ CREATE FUNCTION test_param_names1(a0 integer, a1 text) RETURNS boolean AS $$
assert a0 == args[0] assert a0 == args[0]
assert a1 == args[1] assert a1 == args[1]
return True return True
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_param_names2(u users) RETURNS text AS $$ CREATE FUNCTION test_param_names2(u users) RETURNS text AS $$
assert u == args[0] assert u == args[0]
@ -22,7 +22,7 @@ if isinstance(u, dict):
else: else:
s = str(u) s = str(u)
return s return s
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
-- use deliberately wrong parameter names -- use deliberately wrong parameter names
CREATE FUNCTION test_param_names3(a0 integer) RETURNS boolean AS $$ CREATE FUNCTION test_param_names3(a0 integer) RETURNS boolean AS $$
@ -32,7 +32,7 @@ try:
except NameError as e: except NameError as e:
assert e.args[0].find("a1") > -1 assert e.args[0].find("a1") > -1
return True return True
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT test_param_names0(2,7); SELECT test_param_names0(2,7);

View File

@ -9,7 +9,7 @@ CREATE FUNCTION quote(t text, how text) RETURNS text AS $$
return plpy.quote_ident(t) return plpy.quote_ident(t)
else: else:
raise plpy.Error("unrecognized quote type %s" % how) raise plpy.Error("unrecognized quote type %s" % how)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT quote(t, 'literal') FROM (VALUES SELECT quote(t, 'literal') FROM (VALUES
('abc'), ('abc'),

View File

@ -27,7 +27,7 @@ elif typ == 'obj':
type_record.first = first type_record.first = first
type_record.second = second type_record.second = second
return type_record return type_record
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_type_record_as(typ text, first text, second integer, retnull boolean) RETURNS type_record AS $$ CREATE FUNCTION test_type_record_as(typ text, first text, second integer, retnull boolean) RETURNS type_record AS $$
if retnull: if retnull:
@ -45,20 +45,20 @@ elif typ == 'obj':
return type_record return type_record
elif typ == 'str': elif typ == 'str':
return "('%s',%r)" % (first, second) return "('%s',%r)" % (first, second)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_in_out_params(first in text, second out text) AS $$ CREATE FUNCTION test_in_out_params(first in text, second out text) AS $$
return first + '_in_to_out'; return first + '_in_to_out';
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_in_out_params_multi(first in text, CREATE FUNCTION test_in_out_params_multi(first in text,
second out text, third out text) AS $$ second out text, third out text) AS $$
return (first + '_record_in_to_out_1', first + '_record_in_to_out_2'); return (first + '_record_in_to_out_1', first + '_record_in_to_out_2');
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_inout_params(first inout text) AS $$ CREATE FUNCTION test_inout_params(first inout text) AS $$
return first + '_inout'; return first + '_inout';
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
-- Test tuple returning functions -- Test tuple returning functions
@ -136,14 +136,14 @@ SELECT * FROM test_type_record_as('obj', 'one', 1, false);
CREATE FUNCTION test_type_record_error1() RETURNS type_record AS $$ CREATE FUNCTION test_type_record_error1() RETURNS type_record AS $$
return { 'first': 'first' } return { 'first': 'first' }
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_record_error1(); SELECT * FROM test_type_record_error1();
CREATE FUNCTION test_type_record_error2() RETURNS type_record AS $$ CREATE FUNCTION test_type_record_error2() RETURNS type_record AS $$
return [ 'first' ] return [ 'first' ]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_record_error2(); SELECT * FROM test_type_record_error2();
@ -152,12 +152,12 @@ CREATE FUNCTION test_type_record_error3() RETURNS type_record AS $$
class type_record: pass class type_record: pass
type_record.first = 'first' type_record.first = 'first'
return type_record return type_record
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_record_error3(); SELECT * FROM test_type_record_error3();
CREATE FUNCTION test_type_record_error4() RETURNS type_record AS $$ CREATE FUNCTION test_type_record_error4() RETURNS type_record AS $$
return 'foo' return 'foo'
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_record_error4(); SELECT * FROM test_type_record_error4();

View File

@ -4,21 +4,21 @@
CREATE FUNCTION test_setof_error() RETURNS SETOF text AS $$ CREATE FUNCTION test_setof_error() RETURNS SETOF text AS $$
return 37 return 37
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT test_setof_error(); SELECT test_setof_error();
CREATE FUNCTION test_setof_as_list(count integer, content text) RETURNS SETOF text AS $$ CREATE FUNCTION test_setof_as_list(count integer, content text) RETURNS SETOF text AS $$
return [ content ]*count return [ content ]*count
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_setof_as_tuple(count integer, content text) RETURNS SETOF text AS $$ CREATE FUNCTION test_setof_as_tuple(count integer, content text) RETURNS SETOF text AS $$
t = () t = ()
for i in range(count): for i in range(count):
t += ( content, ) t += ( content, )
return t return t
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_setof_as_iterator(count integer, content text) RETURNS SETOF text AS $$ CREATE FUNCTION test_setof_as_iterator(count integer, content text) RETURNS SETOF text AS $$
class producer: class producer:
@ -27,13 +27,13 @@ class producer:
self.icount = icount self.icount = icount
def __iter__ (self): def __iter__ (self):
return self return self
def next (self): def __next__ (self):
if self.icount == 0: if self.icount == 0:
raise StopIteration raise StopIteration
self.icount -= 1 self.icount -= 1
return self.icontent return self.icontent
return producer(count, content) return producer(count, content)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_setof_spi_in_iterator() RETURNS SETOF text AS CREATE FUNCTION test_setof_spi_in_iterator() RETURNS SETOF text AS
$$ $$
@ -42,7 +42,7 @@ $$
yield s yield s
plpy.execute('select 2') plpy.execute('select 2')
$$ $$
LANGUAGE plpythonu; LANGUAGE plpython3u;
-- Test set returning functions -- Test set returning functions
@ -69,7 +69,7 @@ global x
while x <= lim: while x <= lim:
yield x yield x
x = x + 1 x = x + 1
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT ugly(1, 5); SELECT ugly(1, 5);
@ -81,7 +81,7 @@ CREATE OR REPLACE FUNCTION get_user_records()
RETURNS SETOF users RETURNS SETOF users
AS $$ AS $$
return plpy.execute("SELECT * FROM users ORDER BY username") return plpy.execute("SELECT * FROM users ORDER BY username")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT get_user_records(); SELECT get_user_records();
SELECT * FROM get_user_records(); SELECT * FROM get_user_records();
@ -91,7 +91,7 @@ CREATE OR REPLACE FUNCTION get_user_records2()
RETURNS TABLE(fname text, lname text, username text, userid int) RETURNS TABLE(fname text, lname text, username text, userid int)
AS $$ AS $$
return plpy.execute("SELECT * FROM users ORDER BY username") return plpy.execute("SELECT * FROM users ORDER BY username")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT get_user_records2(); SELECT get_user_records2();
SELECT * FROM get_user_records2(); SELECT * FROM get_user_records2();

View File

@ -7,19 +7,19 @@ CREATE FUNCTION nested_call_one(a text) RETURNS text
'q = "SELECT nested_call_two(''%s'')" % a 'q = "SELECT nested_call_two(''%s'')" % a
r = plpy.execute(q) r = plpy.execute(q)
return r[0]' return r[0]'
LANGUAGE plpythonu ; LANGUAGE plpython3u ;
CREATE FUNCTION nested_call_two(a text) RETURNS text CREATE FUNCTION nested_call_two(a text) RETURNS text
AS AS
'q = "SELECT nested_call_three(''%s'')" % a 'q = "SELECT nested_call_three(''%s'')" % a
r = plpy.execute(q) r = plpy.execute(q)
return r[0]' return r[0]'
LANGUAGE plpythonu ; LANGUAGE plpython3u ;
CREATE FUNCTION nested_call_three(a text) RETURNS text CREATE FUNCTION nested_call_three(a text) RETURNS text
AS AS
'return a' 'return a'
LANGUAGE plpythonu ; LANGUAGE plpython3u ;
-- some spi stuff -- some spi stuff
@ -35,7 +35,7 @@ except Exception as ex:
plpy.error(str(ex)) plpy.error(str(ex))
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION spi_prepared_plan_test_two(a text) RETURNS text CREATE FUNCTION spi_prepared_plan_test_two(a text) RETURNS text
AS AS
@ -49,7 +49,7 @@ except Exception as ex:
plpy.error(str(ex)) plpy.error(str(ex))
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION spi_prepared_plan_test_nested(a text) RETURNS text CREATE FUNCTION spi_prepared_plan_test_nested(a text) RETURNS text
AS AS
@ -64,7 +64,7 @@ except Exception as ex:
plpy.error(str(ex)) plpy.error(str(ex))
return None return None
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION join_sequences(s sequences) RETURNS text CREATE FUNCTION join_sequences(s sequences) RETURNS text
AS AS
@ -77,7 +77,7 @@ for r in rv:
seq = seq + r["sequence"] seq = seq + r["sequence"]
return seq return seq
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION spi_recursive_sum(a int) RETURNS int CREATE FUNCTION spi_recursive_sum(a int) RETURNS int
AS AS
@ -86,7 +86,7 @@ if a > 1:
r = plpy.execute("SELECT spi_recursive_sum(%d) as a" % (a-1))[0]["a"] r = plpy.execute("SELECT spi_recursive_sum(%d) as a" % (a-1))[0]["a"]
return a + r return a + r
' '
LANGUAGE plpythonu; LANGUAGE plpython3u;
-- --
-- spi and nested calls -- spi and nested calls
@ -120,7 +120,7 @@ if result.status() > 0:
return result.nrows() return result.nrows()
else: else:
return None return None
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT result_metadata_test($$SELECT 1 AS foo, '11'::text AS bar UNION SELECT 2, '22'$$); SELECT result_metadata_test($$SELECT 1 AS foo, '11'::text AS bar UNION SELECT 2, '22'$$);
SELECT result_metadata_test($$CREATE TEMPORARY TABLE foo1 (a int, b text)$$); SELECT result_metadata_test($$CREATE TEMPORARY TABLE foo1 (a int, b text)$$);
@ -129,7 +129,7 @@ CREATE FUNCTION result_nrows_test(cmd text) RETURNS int
AS $$ AS $$
result = plpy.execute(cmd) result = plpy.execute(cmd)
return result.nrows() return result.nrows()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT result_nrows_test($$SELECT 1$$); SELECT result_nrows_test($$SELECT 1$$);
SELECT result_nrows_test($$CREATE TEMPORARY TABLE foo2 (a int, b text)$$); SELECT result_nrows_test($$CREATE TEMPORARY TABLE foo2 (a int, b text)$$);
@ -140,7 +140,7 @@ CREATE FUNCTION result_len_test(cmd text) RETURNS int
AS $$ AS $$
result = plpy.execute(cmd) result = plpy.execute(cmd)
return len(result) return len(result)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT result_len_test($$SELECT 1$$); SELECT result_len_test($$SELECT 1$$);
SELECT result_len_test($$CREATE TEMPORARY TABLE foo3 (a int, b text)$$); SELECT result_len_test($$CREATE TEMPORARY TABLE foo3 (a int, b text)$$);
@ -162,7 +162,7 @@ result[-1] = {'c': 1000}
result[:2] = [{'c': 10}, {'c': 100}] result[:2] = [{'c': 10}, {'c': 100}]
plpy.info([item['c'] for item in result[:]]) plpy.info([item['c'] for item in result[:]])
# raises TypeError, but the message differs on Python 2.6, so silence it # raises TypeError, catch so further tests could be added
try: try:
plpy.info(result['foo']) plpy.info(result['foo'])
except TypeError: except TypeError:
@ -170,7 +170,7 @@ except TypeError:
else: else:
assert False, "TypeError not raised" assert False, "TypeError not raised"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT result_subscript_test(); SELECT result_subscript_test();
@ -180,7 +180,7 @@ result = plpy.execute("select 1 where false")
plpy.info(result[:]) plpy.info(result[:])
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT result_empty_test(); SELECT result_empty_test();
@ -189,7 +189,7 @@ AS $$
plan = plpy.prepare(cmd) plan = plpy.prepare(cmd)
result = plpy.execute(plan) result = plpy.execute(plan)
return str(result) return str(result)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT result_str_test($$SELECT 1 AS foo UNION SELECT 2$$); SELECT result_str_test($$SELECT 1 AS foo UNION SELECT 2$$);
SELECT result_str_test($$CREATE TEMPORARY TABLE foo1 (a int, b text)$$); SELECT result_str_test($$CREATE TEMPORARY TABLE foo1 (a int, b text)$$);
@ -203,13 +203,13 @@ for row in res:
if row['lname'] == 'doe': if row['lname'] == 'doe':
does += 1 does += 1
return does return does
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION double_cursor_close() RETURNS int AS $$ CREATE FUNCTION double_cursor_close() RETURNS int AS $$
res = plpy.cursor("select fname, lname from users") res = plpy.cursor("select fname, lname from users")
res.close() res.close()
res.close() res.close()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_fetch() RETURNS int AS $$ CREATE FUNCTION cursor_fetch() RETURNS int AS $$
res = plpy.cursor("select fname, lname from users") res = plpy.cursor("select fname, lname from users")
@ -228,7 +228,7 @@ except StopIteration:
pass pass
else: else:
assert False, "StopIteration not raised" assert False, "StopIteration not raised"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_mix_next_and_fetch() RETURNS int AS $$ CREATE FUNCTION cursor_mix_next_and_fetch() RETURNS int AS $$
res = plpy.cursor("select fname, lname from users order by fname") res = plpy.cursor("select fname, lname from users order by fname")
@ -242,7 +242,7 @@ except AttributeError:
assert item['fname'] == 'rick' assert item['fname'] == 'rick'
assert len(res.fetch(2)) == 1 assert len(res.fetch(2)) == 1
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION fetch_after_close() RETURNS int AS $$ CREATE FUNCTION fetch_after_close() RETURNS int AS $$
res = plpy.cursor("select fname, lname from users") res = plpy.cursor("select fname, lname from users")
@ -253,7 +253,7 @@ except ValueError:
pass pass
else: else:
assert False, "ValueError not raised" assert False, "ValueError not raised"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION next_after_close() RETURNS int AS $$ CREATE FUNCTION next_after_close() RETURNS int AS $$
res = plpy.cursor("select fname, lname from users") res = plpy.cursor("select fname, lname from users")
@ -267,7 +267,7 @@ except ValueError:
pass pass
else: else:
assert False, "ValueError not raised" assert False, "ValueError not raised"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_fetch_next_empty() RETURNS int AS $$ CREATE FUNCTION cursor_fetch_next_empty() RETURNS int AS $$
res = plpy.cursor("select fname, lname from users where false") res = plpy.cursor("select fname, lname from users where false")
@ -281,7 +281,7 @@ except StopIteration:
pass pass
else: else:
assert False, "StopIteration not raised" assert False, "StopIteration not raised"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_plan() RETURNS SETOF text AS $$ CREATE FUNCTION cursor_plan() RETURNS SETOF text AS $$
plan = plpy.prepare( plan = plpy.prepare(
@ -291,13 +291,13 @@ for row in plpy.cursor(plan, ["w"]):
yield row['fname'] yield row['fname']
for row in plan.cursor(["j"]): for row in plan.cursor(["j"]):
yield row['fname'] yield row['fname']
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_plan_wrong_args() RETURNS SETOF text AS $$ CREATE FUNCTION cursor_plan_wrong_args() RETURNS SETOF text AS $$
plan = plpy.prepare("select fname, lname from users where fname like $1 || '%'", plan = plpy.prepare("select fname, lname from users where fname like $1 || '%'",
["text"]) ["text"])
c = plpy.cursor(plan, ["a", "b"]) c = plpy.cursor(plan, ["a", "b"])
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TYPE test_composite_type AS ( CREATE TYPE test_composite_type AS (
a1 int, a1 int,
@ -308,7 +308,7 @@ CREATE OR REPLACE FUNCTION plan_composite_args() RETURNS test_composite_type AS
plan = plpy.prepare("select $1 as c1", ["test_composite_type"]) plan = plpy.prepare("select $1 as c1", ["test_composite_type"])
res = plpy.execute(plan, [{"a1": 3, "a2": "label"}]) res = plpy.execute(plan, [{"a1": 3, "a2": "label"}])
return res[0]["c1"] return res[0]["c1"]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT simple_cursor_test(); SELECT simple_cursor_test();
SELECT double_cursor_close(); SELECT double_cursor_close();

View File

@ -17,7 +17,7 @@ with plpy.subtransaction():
plpy.execute("INSERT INTO subtransaction_tbl VALUES ('oops')") plpy.execute("INSERT INTO subtransaction_tbl VALUES ('oops')")
elif what_error == "Python": elif what_error == "Python":
raise Exception("Python exception") raise Exception("Python exception")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT subtransaction_ctx_test(); SELECT subtransaction_ctx_test();
SELECT * FROM subtransaction_tbl; SELECT * FROM subtransaction_tbl;
@ -45,7 +45,7 @@ with plpy.subtransaction():
raise raise
plpy.notice("Swallowed %s(%r)" % (e.__class__.__name__, e.args[0])) plpy.notice("Swallowed %s(%r)" % (e.__class__.__name__, e.args[0]))
return "ok" return "ok"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT subtransaction_nested_test(); SELECT subtransaction_nested_test();
SELECT * FROM subtransaction_tbl; SELECT * FROM subtransaction_tbl;
@ -65,7 +65,7 @@ with plpy.subtransaction():
plpy.execute("INSERT INTO subtransaction_tbl VALUES (2)") plpy.execute("INSERT INTO subtransaction_tbl VALUES (2)")
plpy.execute("SELECT subtransaction_nested_test('t')") plpy.execute("SELECT subtransaction_nested_test('t')")
return "ok" return "ok"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT subtransaction_deeply_nested_test(); SELECT subtransaction_deeply_nested_test();
SELECT * FROM subtransaction_tbl; SELECT * FROM subtransaction_tbl;
@ -76,25 +76,25 @@ TRUNCATE subtransaction_tbl;
CREATE FUNCTION subtransaction_exit_without_enter() RETURNS void CREATE FUNCTION subtransaction_exit_without_enter() RETURNS void
AS $$ AS $$
plpy.subtransaction().__exit__(None, None, None) plpy.subtransaction().__exit__(None, None, None)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION subtransaction_enter_without_exit() RETURNS void CREATE FUNCTION subtransaction_enter_without_exit() RETURNS void
AS $$ AS $$
plpy.subtransaction().__enter__() plpy.subtransaction().__enter__()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION subtransaction_exit_twice() RETURNS void CREATE FUNCTION subtransaction_exit_twice() RETURNS void
AS $$ AS $$
plpy.subtransaction().__enter__() plpy.subtransaction().__enter__()
plpy.subtransaction().__exit__(None, None, None) plpy.subtransaction().__exit__(None, None, None)
plpy.subtransaction().__exit__(None, None, None) plpy.subtransaction().__exit__(None, None, None)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION subtransaction_enter_twice() RETURNS void CREATE FUNCTION subtransaction_enter_twice() RETURNS void
AS $$ AS $$
plpy.subtransaction().__enter__() plpy.subtransaction().__enter__()
plpy.subtransaction().__enter__() plpy.subtransaction().__enter__()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION subtransaction_exit_same_subtransaction_twice() RETURNS void CREATE FUNCTION subtransaction_exit_same_subtransaction_twice() RETURNS void
AS $$ AS $$
@ -102,7 +102,7 @@ s = plpy.subtransaction()
s.__enter__() s.__enter__()
s.__exit__(None, None, None) s.__exit__(None, None, None)
s.__exit__(None, None, None) s.__exit__(None, None, None)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION subtransaction_enter_same_subtransaction_twice() RETURNS void CREATE FUNCTION subtransaction_enter_same_subtransaction_twice() RETURNS void
AS $$ AS $$
@ -110,14 +110,14 @@ s = plpy.subtransaction()
s.__enter__() s.__enter__()
s.__enter__() s.__enter__()
s.__exit__(None, None, None) s.__exit__(None, None, None)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
-- No warnings here, as the subtransaction gets indeed closed -- No warnings here, as the subtransaction gets indeed closed
CREATE FUNCTION subtransaction_enter_subtransaction_in_with() RETURNS void CREATE FUNCTION subtransaction_enter_subtransaction_in_with() RETURNS void
AS $$ AS $$
with plpy.subtransaction() as s: with plpy.subtransaction() as s:
s.__enter__() s.__enter__()
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION subtransaction_exit_subtransaction_in_with() RETURNS void CREATE FUNCTION subtransaction_exit_subtransaction_in_with() RETURNS void
AS $$ AS $$
@ -126,7 +126,7 @@ try:
s.__exit__(None, None, None) s.__exit__(None, None, None)
except ValueError as e: except ValueError as e:
raise ValueError(e) raise ValueError(e)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT subtransaction_exit_without_enter(); SELECT subtransaction_exit_without_enter();
SELECT subtransaction_enter_without_exit(); SELECT subtransaction_enter_without_exit();
@ -159,7 +159,7 @@ try:
plpy.execute(p, ["wrong"]) plpy.execute(p, ["wrong"])
except plpy.SPIError: except plpy.SPIError:
plpy.warning("Caught a SPI error") plpy.warning("Caught a SPI error")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT subtransaction_mix_explicit_and_implicit(); SELECT subtransaction_mix_explicit_and_implicit();
SELECT * FROM subtransaction_tbl; SELECT * FROM subtransaction_tbl;
@ -172,7 +172,7 @@ AS $$
s = plpy.subtransaction() s = plpy.subtransaction()
s.enter() s.enter()
s.exit(None, None, None) s.exit(None, None, None)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT subtransaction_alternative_names(); SELECT subtransaction_alternative_names();
@ -186,7 +186,7 @@ with plpy.subtransaction():
plpy.execute("INSERT INTO subtransaction_tbl VALUES ('a')") plpy.execute("INSERT INTO subtransaction_tbl VALUES ('a')")
except plpy.SPIError: except plpy.SPIError:
plpy.notice("caught") plpy.notice("caught")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT try_catch_inside_subtransaction(); SELECT try_catch_inside_subtransaction();
SELECT * FROM subtransaction_tbl; SELECT * FROM subtransaction_tbl;
@ -202,7 +202,7 @@ with plpy.subtransaction():
plpy.execute("INSERT INTO subtransaction_tbl VALUES (1)") plpy.execute("INSERT INTO subtransaction_tbl VALUES (1)")
except plpy.SPIError: except plpy.SPIError:
plpy.notice("caught") plpy.notice("caught")
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT pk_violation_inside_subtransaction(); SELECT pk_violation_inside_subtransaction();
SELECT * FROM subtransaction_tbl; SELECT * FROM subtransaction_tbl;
@ -217,7 +217,7 @@ with plpy.subtransaction():
cur.fetch(10) cur.fetch(10)
fetched = cur.fetch(10); fetched = cur.fetch(10);
return int(fetched[5]["i"]) return int(fetched[5]["i"])
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_aborted_subxact() RETURNS int AS $$ CREATE FUNCTION cursor_aborted_subxact() RETURNS int AS $$
try: try:
@ -229,7 +229,7 @@ except plpy.SPIError:
fetched = cur.fetch(10) fetched = cur.fetch(10)
return int(fetched[5]["i"]) return int(fetched[5]["i"])
return 0 # not reached return 0 # not reached
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_plan_aborted_subxact() RETURNS int AS $$ CREATE FUNCTION cursor_plan_aborted_subxact() RETURNS int AS $$
try: try:
@ -243,7 +243,7 @@ except plpy.SPIError:
fetched = cur.fetch(5) fetched = cur.fetch(5)
return fetched[2]["i"] return fetched[2]["i"]
return 0 # not reached return 0 # not reached
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION cursor_close_aborted_subxact() RETURNS boolean AS $$ CREATE FUNCTION cursor_close_aborted_subxact() RETURNS boolean AS $$
try: try:
@ -254,7 +254,7 @@ except plpy.SPIError:
cur.close() cur.close()
return True return True
return False # not reached return False # not reached
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT cursor_in_subxact(); SELECT cursor_in_subxact();
SELECT cursor_aborted_subxact(); SELECT cursor_aborted_subxact();

View File

@ -1,13 +1,13 @@
-- first some tests of basic functionality -- first some tests of basic functionality
CREATE EXTENSION plpython2u; CREATE EXTENSION plpython3u;
-- really stupid function just to get the module loaded -- really stupid function just to get the module loaded
CREATE FUNCTION stupid() RETURNS text AS 'return "zarkon"' LANGUAGE plpythonu; CREATE FUNCTION stupid() RETURNS text AS 'return "zarkon"' LANGUAGE plpython3u;
select stupid(); select stupid();
-- check 2/3 versioning -- check 2/3 versioning
CREATE FUNCTION stupidn() RETURNS text AS 'return "zarkon"' LANGUAGE plpython2u; CREATE FUNCTION stupidn() RETURNS text AS 'return "zarkon"' LANGUAGE plpython3u;
select stupidn(); select stupidn();
@ -21,7 +21,7 @@ for key in keys:
out.append("%s: %s" % (key, u[key])) out.append("%s: %s" % (key, u[key]))
words = a1 + " " + a2 + " => {" + ", ".join(out) + "}" words = a1 + " " + a2 + " => {" + ", ".join(out) + "}"
return words' return words'
LANGUAGE plpythonu; LANGUAGE plpython3u;
select "Argument test #1"(users, fname, lname) from users where lname = 'doe' order by 1; select "Argument test #1"(users, fname, lname) from users where lname = 'doe' order by 1;
@ -32,7 +32,7 @@ $$
contents = list(filter(lambda x: not x.startswith("__"), dir(plpy))) contents = list(filter(lambda x: not x.startswith("__"), dir(plpy)))
contents.sort() contents.sort()
return contents return contents
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
select module_contents(); select module_contents();
@ -47,6 +47,6 @@ plpy.info('info', 37, [1, 2, 3])
plpy.notice('notice') plpy.notice('notice')
plpy.warning('warning') plpy.warning('warning')
plpy.error('error') plpy.error('error')
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT elog_test_basic(); SELECT elog_test_basic();

View File

@ -2,7 +2,7 @@ CREATE TABLE test1 (a int, b text);
CREATE PROCEDURE transaction_test1() CREATE PROCEDURE transaction_test1()
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
for i in range(0, 10): for i in range(0, 10):
plpy.execute("INSERT INTO test1 (a) VALUES (%d)" % i) plpy.execute("INSERT INTO test1 (a) VALUES (%d)" % i)
@ -20,7 +20,7 @@ SELECT * FROM test1;
TRUNCATE test1; TRUNCATE test1;
DO DO
LANGUAGE plpythonu LANGUAGE plpython3u
$$ $$
for i in range(0, 10): for i in range(0, 10):
plpy.execute("INSERT INTO test1 (a) VALUES (%d)" % i) plpy.execute("INSERT INTO test1 (a) VALUES (%d)" % i)
@ -37,7 +37,7 @@ TRUNCATE test1;
-- not allowed in a function -- not allowed in a function
CREATE FUNCTION transaction_test2() RETURNS int CREATE FUNCTION transaction_test2() RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
for i in range(0, 10): for i in range(0, 10):
plpy.execute("INSERT INTO test1 (a) VALUES (%d)" % i) plpy.execute("INSERT INTO test1 (a) VALUES (%d)" % i)
@ -55,7 +55,7 @@ SELECT * FROM test1;
-- also not allowed if procedure is called from a function -- also not allowed if procedure is called from a function
CREATE FUNCTION transaction_test3() RETURNS int CREATE FUNCTION transaction_test3() RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plpy.execute("CALL transaction_test1()") plpy.execute("CALL transaction_test1()")
return 1 return 1
@ -68,9 +68,9 @@ SELECT * FROM test1;
-- DO block inside function -- DO block inside function
CREATE FUNCTION transaction_test4() RETURNS int CREATE FUNCTION transaction_test4() RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plpy.execute("DO LANGUAGE plpythonu $x$ plpy.commit() $x$") plpy.execute("DO LANGUAGE plpython3u $x$ plpy.commit() $x$")
return 1 return 1
$$; $$;
@ -78,7 +78,7 @@ SELECT transaction_test4();
-- commit inside subtransaction (prohibited) -- commit inside subtransaction (prohibited)
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
s = plpy.subtransaction() s = plpy.subtransaction()
s.enter() s.enter()
plpy.commit() plpy.commit()
@ -91,7 +91,7 @@ INSERT INTO test2 VALUES (0), (1), (2), (3), (4);
TRUNCATE test1; TRUNCATE test1;
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"): for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"):
plpy.execute("INSERT INTO test1 (a) VALUES (%s)" % row['x']) plpy.execute("INSERT INTO test1 (a) VALUES (%s)" % row['x'])
plpy.commit() plpy.commit()
@ -106,7 +106,7 @@ SELECT * FROM pg_cursors;
-- error in cursor loop with commit -- error in cursor loop with commit
TRUNCATE test1; TRUNCATE test1;
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"): for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"):
plpy.execute("INSERT INTO test1 (a) VALUES (12/(%s-2))" % row['x']) plpy.execute("INSERT INTO test1 (a) VALUES (12/(%s-2))" % row['x'])
plpy.commit() plpy.commit()
@ -120,7 +120,7 @@ SELECT * FROM pg_cursors;
-- rollback inside cursor loop -- rollback inside cursor loop
TRUNCATE test1; TRUNCATE test1;
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"): for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"):
plpy.execute("INSERT INTO test1 (a) VALUES (%s)" % row['x']) plpy.execute("INSERT INTO test1 (a) VALUES (%s)" % row['x'])
plpy.rollback() plpy.rollback()
@ -134,7 +134,7 @@ SELECT * FROM pg_cursors;
-- first commit then rollback inside cursor loop -- first commit then rollback inside cursor loop
TRUNCATE test1; TRUNCATE test1;
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"): for row in plpy.cursor("SELECT * FROM test2 ORDER BY x"):
plpy.execute("INSERT INTO test1 (a) VALUES (%s)" % row['x']) plpy.execute("INSERT INTO test1 (a) VALUES (%s)" % row['x'])
if row['x'] % 2 == 0: if row['x'] % 2 == 0:
@ -152,7 +152,7 @@ SELECT * FROM pg_cursors;
CREATE TABLE testpk (id int PRIMARY KEY); CREATE TABLE testpk (id int PRIMARY KEY);
CREATE TABLE testfk(f1 int REFERENCES testpk DEFERRABLE INITIALLY DEFERRED); CREATE TABLE testfk(f1 int REFERENCES testpk DEFERRABLE INITIALLY DEFERRED);
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
# this insert will fail during commit: # this insert will fail during commit:
plpy.execute("INSERT INTO testfk VALUES (0)") plpy.execute("INSERT INTO testfk VALUES (0)")
plpy.commit() plpy.commit()
@ -162,7 +162,7 @@ $$;
SELECT * FROM testpk; SELECT * FROM testpk;
SELECT * FROM testfk; SELECT * FROM testfk;
DO LANGUAGE plpythonu $$ DO LANGUAGE plpython3u $$
# this insert will fail during commit: # this insert will fail during commit:
plpy.execute("INSERT INTO testfk VALUES (0)") plpy.execute("INSERT INTO testfk VALUES (0)")
try: try:

View File

@ -16,7 +16,7 @@ if TD["new"]["fname"] == "william":
TD["new"]["fname"] = TD["args"][0] TD["new"]["fname"] = TD["args"][0]
rv = "MODIFY" rv = "MODIFY"
return rv' return rv'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION users_update() returns trigger CREATE FUNCTION users_update() returns trigger
@ -25,7 +25,7 @@ CREATE FUNCTION users_update() returns trigger
if TD["old"]["fname"] != TD["new"]["fname"] and TD["old"]["fname"] == TD["args"][0]: if TD["old"]["fname"] != TD["new"]["fname"] and TD["old"]["fname"] == TD["args"][0]:
return "SKIP" return "SKIP"
return None' return None'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE FUNCTION users_delete() RETURNS trigger CREATE FUNCTION users_delete() RETURNS trigger
@ -33,7 +33,7 @@ CREATE FUNCTION users_delete() RETURNS trigger
'if TD["old"]["fname"] == TD["args"][0]: 'if TD["old"]["fname"] == TD["args"][0]:
return "SKIP" return "SKIP"
return None' return None'
LANGUAGE plpythonu; LANGUAGE plpython3u;
CREATE TRIGGER users_insert_trig BEFORE INSERT ON users FOR EACH ROW CREATE TRIGGER users_insert_trig BEFORE INSERT ON users FOR EACH ROW
@ -72,7 +72,7 @@ CREATE TABLE trigger_test_generated (
j int GENERATED ALWAYS AS (i * 2) STORED j int GENERATED ALWAYS AS (i * 2) STORED
); );
CREATE FUNCTION trigger_data() RETURNS trigger LANGUAGE plpythonu AS $$ CREATE FUNCTION trigger_data() RETURNS trigger LANGUAGE plpython3u AS $$
if 'relid' in TD: if 'relid' in TD:
TD['relid'] = "bogus:12345" TD['relid'] = "bogus:12345"
@ -157,7 +157,7 @@ INSERT INTO trigger_test VALUES (0, 'zero');
CREATE FUNCTION stupid1() RETURNS trigger CREATE FUNCTION stupid1() RETURNS trigger
AS $$ AS $$
return 37 return 37
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger1 CREATE TRIGGER stupid_trigger1
BEFORE INSERT ON trigger_test BEFORE INSERT ON trigger_test
@ -173,7 +173,7 @@ DROP TRIGGER stupid_trigger1 ON trigger_test;
CREATE FUNCTION stupid2() RETURNS trigger CREATE FUNCTION stupid2() RETURNS trigger
AS $$ AS $$
return "MODIFY" return "MODIFY"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger2 CREATE TRIGGER stupid_trigger2
BEFORE DELETE ON trigger_test BEFORE DELETE ON trigger_test
@ -191,7 +191,7 @@ INSERT INTO trigger_test VALUES (0, 'zero');
CREATE FUNCTION stupid3() RETURNS trigger CREATE FUNCTION stupid3() RETURNS trigger
AS $$ AS $$
return "foo" return "foo"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger3 CREATE TRIGGER stupid_trigger3
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
@ -206,8 +206,8 @@ DROP TRIGGER stupid_trigger3 ON trigger_test;
CREATE FUNCTION stupid3u() RETURNS trigger CREATE FUNCTION stupid3u() RETURNS trigger
AS $$ AS $$
return u"foo" return "foo"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger3 CREATE TRIGGER stupid_trigger3
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
@ -224,7 +224,7 @@ CREATE FUNCTION stupid4() RETURNS trigger
AS $$ AS $$
del TD["new"] del TD["new"]
return "MODIFY"; return "MODIFY";
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger4 CREATE TRIGGER stupid_trigger4
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
@ -241,7 +241,7 @@ CREATE FUNCTION stupid5() RETURNS trigger
AS $$ AS $$
TD["new"] = ['foo', 'bar'] TD["new"] = ['foo', 'bar']
return "MODIFY"; return "MODIFY";
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger5 CREATE TRIGGER stupid_trigger5
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
@ -258,7 +258,7 @@ CREATE FUNCTION stupid6() RETURNS trigger
AS $$ AS $$
TD["new"] = {1: 'foo', 2: 'bar'} TD["new"] = {1: 'foo', 2: 'bar'}
return "MODIFY"; return "MODIFY";
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger6 CREATE TRIGGER stupid_trigger6
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
@ -275,7 +275,7 @@ CREATE FUNCTION stupid7() RETURNS trigger
AS $$ AS $$
TD["new"] = {'v': 'foo', 'a': 'bar'} TD["new"] = {'v': 'foo', 'a': 'bar'}
return "MODIFY"; return "MODIFY";
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger7 CREATE TRIGGER stupid_trigger7
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
@ -290,9 +290,9 @@ DROP TRIGGER stupid_trigger7 ON trigger_test;
CREATE FUNCTION stupid7u() RETURNS trigger CREATE FUNCTION stupid7u() RETURNS trigger
AS $$ AS $$
TD["new"] = {u'v': 'foo', u'a': 'bar'} TD["new"] = {'v': 'foo', 'a': 'bar'}
return "MODIFY" return "MODIFY"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER stupid_trigger7 CREATE TRIGGER stupid_trigger7
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
@ -318,7 +318,7 @@ CREATE FUNCTION test_null() RETURNS trigger
AS $$ AS $$
TD["new"]['v'] = None TD["new"]['v'] = None
return "MODIFY" return "MODIFY"
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER test_null_trigger CREATE TRIGGER test_null_trigger
BEFORE UPDATE ON trigger_test BEFORE UPDATE ON trigger_test
@ -341,7 +341,7 @@ SET DateStyle = 'ISO';
CREATE FUNCTION set_modif_time() RETURNS trigger AS $$ CREATE FUNCTION set_modif_time() RETURNS trigger AS $$
TD['new']['modif_time'] = '2010-10-13 21:57:28.930486' TD['new']['modif_time'] = '2010-10-13 21:57:28.930486'
return 'MODIFY' return 'MODIFY'
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TABLE pb (a TEXT, modif_time TIMESTAMP(0) WITHOUT TIME ZONE); CREATE TABLE pb (a TEXT, modif_time TIMESTAMP(0) WITHOUT TIME ZONE);
@ -365,7 +365,7 @@ CREATE FUNCTION composite_trigger_f() RETURNS trigger AS $$
TD['new']['f1'] = (3, False) TD['new']['f1'] = (3, False)
TD['new']['f2'] = {'k': 7, 'l': 'yes', 'ignored': 10} TD['new']['f2'] = {'k': 7, 'l': 'yes', 'ignored': 10}
return 'MODIFY' return 'MODIFY'
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER composite_trigger BEFORE INSERT ON composite_trigger_test CREATE TRIGGER composite_trigger BEFORE INSERT ON composite_trigger_test
FOR EACH ROW EXECUTE PROCEDURE composite_trigger_f(); FOR EACH ROW EXECUTE PROCEDURE composite_trigger_f();
@ -380,7 +380,7 @@ CREATE TABLE composite_trigger_noop_test (f1 comp1, f2 comp2);
CREATE FUNCTION composite_trigger_noop_f() RETURNS trigger AS $$ CREATE FUNCTION composite_trigger_noop_f() RETURNS trigger AS $$
return 'MODIFY' return 'MODIFY'
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER composite_trigger_noop BEFORE INSERT ON composite_trigger_noop_test CREATE TRIGGER composite_trigger_noop BEFORE INSERT ON composite_trigger_noop_test
FOR EACH ROW EXECUTE PROCEDURE composite_trigger_noop_f(); FOR EACH ROW EXECUTE PROCEDURE composite_trigger_noop_f();
@ -399,7 +399,7 @@ CREATE TABLE composite_trigger_nested_test(c comp3);
CREATE FUNCTION composite_trigger_nested_f() RETURNS trigger AS $$ CREATE FUNCTION composite_trigger_nested_f() RETURNS trigger AS $$
return 'MODIFY' return 'MODIFY'
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE TRIGGER composite_trigger_nested BEFORE INSERT ON composite_trigger_nested_test CREATE TRIGGER composite_trigger_nested BEFORE INSERT ON composite_trigger_nested_test
FOR EACH ROW EXECUTE PROCEDURE composite_trigger_nested_f(); FOR EACH ROW EXECUTE PROCEDURE composite_trigger_nested_f();
@ -410,7 +410,7 @@ INSERT INTO composite_trigger_nested_test VALUES (ROW(ROW(NULL, 't'), ROW(1, 'f'
SELECT * FROM composite_trigger_nested_test; SELECT * FROM composite_trigger_nested_test;
-- check that using a function as a trigger over two tables works correctly -- check that using a function as a trigger over two tables works correctly
CREATE FUNCTION trig1234() RETURNS trigger LANGUAGE plpythonu AS $$ CREATE FUNCTION trig1234() RETURNS trigger LANGUAGE plpython3u AS $$
TD["new"]["data"] = '1234' TD["new"]["data"] = '1234'
return 'MODIFY' return 'MODIFY'
$$; $$;
@ -432,7 +432,7 @@ SELECT * FROM b;
CREATE TABLE transition_table_test (id int, name text); CREATE TABLE transition_table_test (id int, name text);
INSERT INTO transition_table_test VALUES (1, 'a'); INSERT INTO transition_table_test VALUES (1, 'a');
CREATE FUNCTION transition_table_test_f() RETURNS trigger LANGUAGE plpythonu AS CREATE FUNCTION transition_table_test_f() RETURNS trigger LANGUAGE plpython3u AS
$$ $$
rv = plpy.execute("SELECT * FROM old_table") rv = plpy.execute("SELECT * FROM old_table")
assert(rv.nrows() == 1) assert(rv.nrows() == 1)
@ -455,7 +455,7 @@ DROP FUNCTION transition_table_test_f();
-- dealing with generated columns -- dealing with generated columns
CREATE FUNCTION generated_test_func1() RETURNS trigger CREATE FUNCTION generated_test_func1() RETURNS trigger
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
TD['new']['j'] = 5 # not allowed TD['new']['j'] = 5 # not allowed
return 'MODIFY' return 'MODIFY'

View File

@ -9,7 +9,7 @@
CREATE FUNCTION test_type_conversion_bool(x bool) RETURNS bool AS $$ CREATE FUNCTION test_type_conversion_bool(x bool) RETURNS bool AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_bool(true); SELECT * FROM test_type_conversion_bool(true);
SELECT * FROM test_type_conversion_bool(false); SELECT * FROM test_type_conversion_bool(false);
@ -35,7 +35,7 @@ elif n == 5:
ret = [0] ret = [0]
plpy.info(ret, not not ret) plpy.info(ret, not not ret)
return ret return ret
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_bool_other(0); SELECT * FROM test_type_conversion_bool_other(0);
SELECT * FROM test_type_conversion_bool_other(1); SELECT * FROM test_type_conversion_bool_other(1);
@ -48,7 +48,7 @@ SELECT * FROM test_type_conversion_bool_other(5);
CREATE FUNCTION test_type_conversion_char(x char) RETURNS char AS $$ CREATE FUNCTION test_type_conversion_char(x char) RETURNS char AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_char('a'); SELECT * FROM test_type_conversion_char('a');
SELECT * FROM test_type_conversion_char(null); SELECT * FROM test_type_conversion_char(null);
@ -57,7 +57,7 @@ SELECT * FROM test_type_conversion_char(null);
CREATE FUNCTION test_type_conversion_int2(x int2) RETURNS int2 AS $$ CREATE FUNCTION test_type_conversion_int2(x int2) RETURNS int2 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_int2(100::int2); SELECT * FROM test_type_conversion_int2(100::int2);
SELECT * FROM test_type_conversion_int2(-100::int2); SELECT * FROM test_type_conversion_int2(-100::int2);
@ -67,7 +67,7 @@ SELECT * FROM test_type_conversion_int2(null);
CREATE FUNCTION test_type_conversion_int4(x int4) RETURNS int4 AS $$ CREATE FUNCTION test_type_conversion_int4(x int4) RETURNS int4 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_int4(100); SELECT * FROM test_type_conversion_int4(100);
SELECT * FROM test_type_conversion_int4(-100); SELECT * FROM test_type_conversion_int4(-100);
@ -77,7 +77,7 @@ SELECT * FROM test_type_conversion_int4(null);
CREATE FUNCTION test_type_conversion_int8(x int8) RETURNS int8 AS $$ CREATE FUNCTION test_type_conversion_int8(x int8) RETURNS int8 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_int8(100); SELECT * FROM test_type_conversion_int8(100);
SELECT * FROM test_type_conversion_int8(-100); SELECT * FROM test_type_conversion_int8(-100);
@ -90,7 +90,7 @@ CREATE FUNCTION test_type_conversion_numeric(x numeric) RETURNS numeric AS $$
# between decimal and cdecimal # between decimal and cdecimal
plpy.info(str(x), x.__class__.__name__) plpy.info(str(x), x.__class__.__name__)
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_numeric(100); SELECT * FROM test_type_conversion_numeric(100);
SELECT * FROM test_type_conversion_numeric(-100); SELECT * FROM test_type_conversion_numeric(-100);
@ -105,7 +105,7 @@ SELECT * FROM test_type_conversion_numeric(null);
CREATE FUNCTION test_type_conversion_float4(x float4) RETURNS float4 AS $$ CREATE FUNCTION test_type_conversion_float4(x float4) RETURNS float4 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_float4(100); SELECT * FROM test_type_conversion_float4(100);
SELECT * FROM test_type_conversion_float4(-100); SELECT * FROM test_type_conversion_float4(-100);
@ -116,7 +116,7 @@ SELECT * FROM test_type_conversion_float4(null);
CREATE FUNCTION test_type_conversion_float8(x float8) RETURNS float8 AS $$ CREATE FUNCTION test_type_conversion_float8(x float8) RETURNS float8 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_float8(100); SELECT * FROM test_type_conversion_float8(100);
SELECT * FROM test_type_conversion_float8(-100); SELECT * FROM test_type_conversion_float8(-100);
@ -128,7 +128,7 @@ SELECT * FROM test_type_conversion_float8(100100100.654321);
CREATE FUNCTION test_type_conversion_oid(x oid) RETURNS oid AS $$ CREATE FUNCTION test_type_conversion_oid(x oid) RETURNS oid AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_oid(100); SELECT * FROM test_type_conversion_oid(100);
SELECT * FROM test_type_conversion_oid(2147483649); SELECT * FROM test_type_conversion_oid(2147483649);
@ -138,7 +138,7 @@ SELECT * FROM test_type_conversion_oid(null);
CREATE FUNCTION test_type_conversion_text(x text) RETURNS text AS $$ CREATE FUNCTION test_type_conversion_text(x text) RETURNS text AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_text('hello world'); SELECT * FROM test_type_conversion_text('hello world');
SELECT * FROM test_type_conversion_text(null); SELECT * FROM test_type_conversion_text(null);
@ -147,7 +147,7 @@ SELECT * FROM test_type_conversion_text(null);
CREATE FUNCTION test_type_conversion_bytea(x bytea) RETURNS bytea AS $$ CREATE FUNCTION test_type_conversion_bytea(x bytea) RETURNS bytea AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_bytea('hello world'); SELECT * FROM test_type_conversion_bytea('hello world');
SELECT * FROM test_type_conversion_bytea(E'null\\000byte'); SELECT * FROM test_type_conversion_bytea(E'null\\000byte');
@ -157,7 +157,7 @@ SELECT * FROM test_type_conversion_bytea(null);
CREATE FUNCTION test_type_marshal() RETURNS bytea AS $$ CREATE FUNCTION test_type_marshal() RETURNS bytea AS $$
import marshal import marshal
return marshal.dumps('hello world') return marshal.dumps('hello world')
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_type_unmarshal(x bytea) RETURNS text AS $$ CREATE FUNCTION test_type_unmarshal(x bytea) RETURNS text AS $$
import marshal import marshal
@ -165,7 +165,7 @@ try:
return marshal.loads(x) return marshal.loads(x)
except ValueError as e: except ValueError as e:
return 'FAILED: ' + str(e) return 'FAILED: ' + str(e)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT test_type_unmarshal(x) FROM test_type_marshal() x; SELECT test_type_unmarshal(x) FROM test_type_marshal() x;
@ -178,7 +178,7 @@ CREATE DOMAIN booltrue AS bool CHECK (VALUE IS TRUE OR VALUE IS NULL);
CREATE FUNCTION test_type_conversion_booltrue(x booltrue, y bool) RETURNS booltrue AS $$ CREATE FUNCTION test_type_conversion_booltrue(x booltrue, y bool) RETURNS booltrue AS $$
return y return y
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_booltrue(true, true); SELECT * FROM test_type_conversion_booltrue(true, true);
SELECT * FROM test_type_conversion_booltrue(false, true); SELECT * FROM test_type_conversion_booltrue(false, true);
@ -190,7 +190,7 @@ CREATE DOMAIN uint2 AS int2 CHECK (VALUE >= 0);
CREATE FUNCTION test_type_conversion_uint2(x uint2, y int) RETURNS uint2 AS $$ CREATE FUNCTION test_type_conversion_uint2(x uint2, y int) RETURNS uint2 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return y return y
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_uint2(100::uint2, 50); SELECT * FROM test_type_conversion_uint2(100::uint2, 50);
SELECT * FROM test_type_conversion_uint2(100::uint2, -50); SELECT * FROM test_type_conversion_uint2(100::uint2, -50);
@ -201,7 +201,7 @@ CREATE DOMAIN nnint AS int CHECK (VALUE IS NOT NULL);
CREATE FUNCTION test_type_conversion_nnint(x nnint, y int) RETURNS nnint AS $$ CREATE FUNCTION test_type_conversion_nnint(x nnint, y int) RETURNS nnint AS $$
return y return y
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_nnint(10, 20); SELECT * FROM test_type_conversion_nnint(10, 20);
SELECT * FROM test_type_conversion_nnint(null, 20); SELECT * FROM test_type_conversion_nnint(null, 20);
@ -213,7 +213,7 @@ CREATE DOMAIN bytea10 AS bytea CHECK (octet_length(VALUE) = 10 AND VALUE IS NOT
CREATE FUNCTION test_type_conversion_bytea10(x bytea10, y bytea) RETURNS bytea10 AS $$ CREATE FUNCTION test_type_conversion_bytea10(x bytea10, y bytea) RETURNS bytea10 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return y return y
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_bytea10('hello wold', 'hello wold'); SELECT * FROM test_type_conversion_bytea10('hello wold', 'hello wold');
SELECT * FROM test_type_conversion_bytea10('hello world', 'hello wold'); SELECT * FROM test_type_conversion_bytea10('hello world', 'hello wold');
@ -229,7 +229,7 @@ SELECT * FROM test_type_conversion_bytea10('hello word', null);
CREATE FUNCTION test_type_conversion_array_int4(x int4[]) RETURNS int4[] AS $$ CREATE FUNCTION test_type_conversion_array_int4(x int4[]) RETURNS int4[] AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_int4(ARRAY[0, 100]); SELECT * FROM test_type_conversion_array_int4(ARRAY[0, 100]);
SELECT * FROM test_type_conversion_array_int4(ARRAY[0,-100,55]); SELECT * FROM test_type_conversion_array_int4(ARRAY[0,-100,55]);
@ -243,14 +243,14 @@ SELECT * FROM test_type_conversion_array_int4('[2:4]={1,2,3}');
CREATE FUNCTION test_type_conversion_array_int8(x int8[]) RETURNS int8[] AS $$ CREATE FUNCTION test_type_conversion_array_int8(x int8[]) RETURNS int8[] AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_int8(ARRAY[[[1,2,NULL],[NULL,5,6]],[[NULL,8,9],[10,11,12]]]::int8[]); SELECT * FROM test_type_conversion_array_int8(ARRAY[[[1,2,NULL],[NULL,5,6]],[[NULL,8,9],[10,11,12]]]::int8[]);
CREATE FUNCTION test_type_conversion_array_date(x date[]) RETURNS date[] AS $$ CREATE FUNCTION test_type_conversion_array_date(x date[]) RETURNS date[] AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_date(ARRAY[[['2016-09-21','2016-09-22',NULL],[NULL,'2016-10-21','2016-10-22']], SELECT * FROM test_type_conversion_array_date(ARRAY[[['2016-09-21','2016-09-22',NULL],[NULL,'2016-10-21','2016-10-22']],
[[NULL,'2016-11-21','2016-10-21'],['2015-09-21','2015-09-22','2014-09-21']]]::date[]); [[NULL,'2016-11-21','2016-10-21'],['2015-09-21','2015-09-22','2014-09-21']]]::date[]);
@ -258,7 +258,7 @@ SELECT * FROM test_type_conversion_array_date(ARRAY[[['2016-09-21','2016-09-22',
CREATE FUNCTION test_type_conversion_array_timestamp(x timestamp[]) RETURNS timestamp[] AS $$ CREATE FUNCTION test_type_conversion_array_timestamp(x timestamp[]) RETURNS timestamp[] AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_timestamp(ARRAY[[['2016-09-21 15:34:24.078792-04','2016-10-22 11:34:24.078795-04',NULL], SELECT * FROM test_type_conversion_array_timestamp(ARRAY[[['2016-09-21 15:34:24.078792-04','2016-10-22 11:34:24.078795-04',NULL],
[NULL,'2016-10-21 11:34:25.078792-04','2016-10-21 11:34:24.098792-04']], [NULL,'2016-10-21 11:34:25.078792-04','2016-10-21 11:34:24.098792-04']],
@ -270,7 +270,7 @@ CREATE OR REPLACE FUNCTION pyreturnmultidemint4(h int4, i int4, j int4, k int4 )
m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)] m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)]
plpy.info(m, type(m)) plpy.info(m, type(m))
return m return m
$BODY$ LANGUAGE plpythonu; $BODY$ LANGUAGE plpython3u;
select pyreturnmultidemint4(8,5,3,2); select pyreturnmultidemint4(8,5,3,2);
@ -278,7 +278,7 @@ CREATE OR REPLACE FUNCTION pyreturnmultidemint8(h int4, i int4, j int4, k int4 )
m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)] m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)]
plpy.info(m, type(m)) plpy.info(m, type(m))
return m return m
$BODY$ LANGUAGE plpythonu; $BODY$ LANGUAGE plpython3u;
select pyreturnmultidemint8(5,5,3,2); select pyreturnmultidemint8(5,5,3,2);
@ -286,7 +286,7 @@ CREATE OR REPLACE FUNCTION pyreturnmultidemfloat4(h int4, i int4, j int4, k int4
m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)] m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)]
plpy.info(m, type(m)) plpy.info(m, type(m))
return m return m
$BODY$ LANGUAGE plpythonu; $BODY$ LANGUAGE plpython3u;
select pyreturnmultidemfloat4(6,5,3,2); select pyreturnmultidemfloat4(6,5,3,2);
@ -294,14 +294,14 @@ CREATE OR REPLACE FUNCTION pyreturnmultidemfloat8(h int4, i int4, j int4, k int4
m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)] m = [[[[x for x in range(h)] for y in range(i)] for z in range(j)] for w in range(k)]
plpy.info(m, type(m)) plpy.info(m, type(m))
return m return m
$BODY$ LANGUAGE plpythonu; $BODY$ LANGUAGE plpython3u;
select pyreturnmultidemfloat8(7,5,3,2); select pyreturnmultidemfloat8(7,5,3,2);
CREATE FUNCTION test_type_conversion_array_text(x text[]) RETURNS text[] AS $$ CREATE FUNCTION test_type_conversion_array_text(x text[]) RETURNS text[] AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_text(ARRAY['foo', 'bar']); SELECT * FROM test_type_conversion_array_text(ARRAY['foo', 'bar']);
SELECT * FROM test_type_conversion_array_text(ARRAY[['foo', 'bar'],['foo2', 'bar2']]); SELECT * FROM test_type_conversion_array_text(ARRAY[['foo', 'bar'],['foo2', 'bar2']]);
@ -310,59 +310,59 @@ SELECT * FROM test_type_conversion_array_text(ARRAY[['foo', 'bar'],['foo2', 'bar
CREATE FUNCTION test_type_conversion_array_bytea(x bytea[]) RETURNS bytea[] AS $$ CREATE FUNCTION test_type_conversion_array_bytea(x bytea[]) RETURNS bytea[] AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_bytea(ARRAY[E'\\xdeadbeef'::bytea, NULL]); SELECT * FROM test_type_conversion_array_bytea(ARRAY[E'\\xdeadbeef'::bytea, NULL]);
CREATE FUNCTION test_type_conversion_array_mixed1() RETURNS text[] AS $$ CREATE FUNCTION test_type_conversion_array_mixed1() RETURNS text[] AS $$
return [123, 'abc'] return [123, 'abc']
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_mixed1(); SELECT * FROM test_type_conversion_array_mixed1();
CREATE FUNCTION test_type_conversion_array_mixed2() RETURNS int[] AS $$ CREATE FUNCTION test_type_conversion_array_mixed2() RETURNS int[] AS $$
return [123, 'abc'] return [123, 'abc']
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_mixed2(); SELECT * FROM test_type_conversion_array_mixed2();
CREATE FUNCTION test_type_conversion_mdarray_malformed() RETURNS int[] AS $$ CREATE FUNCTION test_type_conversion_mdarray_malformed() RETURNS int[] AS $$
return [[1,2,3],[4,5]] return [[1,2,3],[4,5]]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_mdarray_malformed(); SELECT * FROM test_type_conversion_mdarray_malformed();
CREATE FUNCTION test_type_conversion_mdarray_toodeep() RETURNS int[] AS $$ CREATE FUNCTION test_type_conversion_mdarray_toodeep() RETURNS int[] AS $$
return [[[[[[[1]]]]]]] return [[[[[[[1]]]]]]]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_mdarray_toodeep(); SELECT * FROM test_type_conversion_mdarray_toodeep();
CREATE FUNCTION test_type_conversion_array_record() RETURNS type_record[] AS $$ CREATE FUNCTION test_type_conversion_array_record() RETURNS type_record[] AS $$
return [{'first': 'one', 'second': 42}, {'first': 'two', 'second': 11}] return [{'first': 'one', 'second': 42}, {'first': 'two', 'second': 11}]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_record(); SELECT * FROM test_type_conversion_array_record();
CREATE FUNCTION test_type_conversion_array_string() RETURNS text[] AS $$ CREATE FUNCTION test_type_conversion_array_string() RETURNS text[] AS $$
return 'abc' return 'abc'
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_string(); SELECT * FROM test_type_conversion_array_string();
CREATE FUNCTION test_type_conversion_array_tuple() RETURNS text[] AS $$ CREATE FUNCTION test_type_conversion_array_tuple() RETURNS text[] AS $$
return ('abc', 'def') return ('abc', 'def')
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_tuple(); SELECT * FROM test_type_conversion_array_tuple();
CREATE FUNCTION test_type_conversion_array_error() RETURNS int[] AS $$ CREATE FUNCTION test_type_conversion_array_error() RETURNS int[] AS $$
return 5 return 5
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_error(); SELECT * FROM test_type_conversion_array_error();
@ -376,14 +376,14 @@ CREATE DOMAIN ordered_pair_domain AS integer[] CHECK (array_length(VALUE,1)=2 AN
CREATE FUNCTION test_type_conversion_array_domain(x ordered_pair_domain) RETURNS ordered_pair_domain AS $$ CREATE FUNCTION test_type_conversion_array_domain(x ordered_pair_domain) RETURNS ordered_pair_domain AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x return x
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_domain(ARRAY[0, 100]::ordered_pair_domain); SELECT * FROM test_type_conversion_array_domain(ARRAY[0, 100]::ordered_pair_domain);
SELECT * FROM test_type_conversion_array_domain(NULL::ordered_pair_domain); SELECT * FROM test_type_conversion_array_domain(NULL::ordered_pair_domain);
CREATE FUNCTION test_type_conversion_array_domain_check_violation() RETURNS ordered_pair_domain AS $$ CREATE FUNCTION test_type_conversion_array_domain_check_violation() RETURNS ordered_pair_domain AS $$
return [2,1] return [2,1]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT * FROM test_type_conversion_array_domain_check_violation(); SELECT * FROM test_type_conversion_array_domain_check_violation();
@ -394,13 +394,13 @@ SELECT * FROM test_type_conversion_array_domain_check_violation();
CREATE FUNCTION test_read_uint2_array(x uint2[]) RETURNS uint2 AS $$ CREATE FUNCTION test_read_uint2_array(x uint2[]) RETURNS uint2 AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x[0] return x[0]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
select test_read_uint2_array(array[1::uint2]); select test_read_uint2_array(array[1::uint2]);
CREATE FUNCTION test_build_uint2_array(x int2) RETURNS uint2[] AS $$ CREATE FUNCTION test_build_uint2_array(x int2) RETURNS uint2[] AS $$
return [x, x] return [x, x]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
select test_build_uint2_array(1::int2); select test_build_uint2_array(1::int2);
select test_build_uint2_array(-1::int2); -- fail select test_build_uint2_array(-1::int2); -- fail
@ -413,7 +413,7 @@ select test_build_uint2_array(-1::int2); -- fail
CREATE FUNCTION test_type_conversion_domain_array(x integer[]) CREATE FUNCTION test_type_conversion_domain_array(x integer[])
RETURNS ordered_pair_domain[] AS $$ RETURNS ordered_pair_domain[] AS $$
return [x, x] return [x, x]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
select test_type_conversion_domain_array(array[2,4]); select test_type_conversion_domain_array(array[2,4]);
select test_type_conversion_domain_array(array[4,2]); -- fail select test_type_conversion_domain_array(array[4,2]); -- fail
@ -422,7 +422,7 @@ CREATE FUNCTION test_type_conversion_domain_array2(x ordered_pair_domain)
RETURNS integer AS $$ RETURNS integer AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x[1] return x[1]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
select test_type_conversion_domain_array2(array[2,4]); select test_type_conversion_domain_array2(array[2,4]);
select test_type_conversion_domain_array2(array[4,2]); -- fail select test_type_conversion_domain_array2(array[4,2]); -- fail
@ -431,7 +431,7 @@ CREATE FUNCTION test_type_conversion_array_domain_array(x ordered_pair_domain[])
RETURNS ordered_pair_domain AS $$ RETURNS ordered_pair_domain AS $$
plpy.info(x, type(x)) plpy.info(x, type(x))
return x[0] return x[0]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
select test_type_conversion_array_domain_array(array[array[2,4]::ordered_pair_domain]); select test_type_conversion_array_domain_array(array[array[2,4]::ordered_pair_domain]);
@ -450,7 +450,7 @@ INSERT INTO employee VALUES ('John', 100, 10), ('Mary', 200, 10);
CREATE OR REPLACE FUNCTION test_composite_table_input(e employee) RETURNS integer AS $$ CREATE OR REPLACE FUNCTION test_composite_table_input(e employee) RETURNS integer AS $$
return e['basesalary'] + e['bonus'] return e['basesalary'] + e['bonus']
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT name, test_composite_table_input(employee.*) FROM employee; SELECT name, test_composite_table_input(employee.*) FROM employee;
@ -470,7 +470,7 @@ CREATE TYPE named_pair AS (
CREATE OR REPLACE FUNCTION test_composite_type_input(p named_pair) RETURNS integer AS $$ CREATE OR REPLACE FUNCTION test_composite_type_input(p named_pair) RETURNS integer AS $$
return sum(p.values()) return sum(p.values())
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT test_composite_type_input(row(1, 2)); SELECT test_composite_type_input(row(1, 2));
@ -487,7 +487,7 @@ CREATE TYPE nnint_container AS (f1 int, f2 nnint);
CREATE FUNCTION nnint_test(x int, y int) RETURNS nnint_container AS $$ CREATE FUNCTION nnint_test(x int, y int) RETURNS nnint_container AS $$
return {'f1': x, 'f2': y} return {'f1': x, 'f2': y}
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT nnint_test(null, 3); SELECT nnint_test(null, 3);
SELECT nnint_test(3, null); -- fail SELECT nnint_test(3, null); -- fail
@ -501,21 +501,21 @@ CREATE DOMAIN ordered_named_pair AS named_pair_2 CHECK((VALUE).i <= (VALUE).j);
CREATE FUNCTION read_ordered_named_pair(p ordered_named_pair) RETURNS integer AS $$ CREATE FUNCTION read_ordered_named_pair(p ordered_named_pair) RETURNS integer AS $$
return p['i'] + p['j'] return p['i'] + p['j']
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT read_ordered_named_pair(row(1, 2)); SELECT read_ordered_named_pair(row(1, 2));
SELECT read_ordered_named_pair(row(2, 1)); -- fail SELECT read_ordered_named_pair(row(2, 1)); -- fail
CREATE FUNCTION build_ordered_named_pair(i int, j int) RETURNS ordered_named_pair AS $$ CREATE FUNCTION build_ordered_named_pair(i int, j int) RETURNS ordered_named_pair AS $$
return {'i': i, 'j': j} return {'i': i, 'j': j}
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT build_ordered_named_pair(1,2); SELECT build_ordered_named_pair(1,2);
SELECT build_ordered_named_pair(2,1); -- fail SELECT build_ordered_named_pair(2,1); -- fail
CREATE FUNCTION build_ordered_named_pairs(i int, j int) RETURNS ordered_named_pair[] AS $$ CREATE FUNCTION build_ordered_named_pairs(i int, j int) RETURNS ordered_named_pair[] AS $$
return [{'i': i, 'j': j}, {'i': i, 'j': j+1}] return [{'i': i, 'j': j}, {'i': i, 'j': j+1}]
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
SELECT build_ordered_named_pairs(1,2); SELECT build_ordered_named_pairs(1,2);
SELECT build_ordered_named_pairs(2,1); -- fail SELECT build_ordered_named_pairs(2,1); -- fail
@ -526,7 +526,7 @@ SELECT build_ordered_named_pairs(2,1); -- fail
-- --
CREATE OR REPLACE FUNCTION test_prep_bool_input() RETURNS int CREATE OR REPLACE FUNCTION test_prep_bool_input() RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plan = plpy.prepare("SELECT CASE WHEN $1 THEN 1 ELSE 0 END AS val", ['boolean']) plan = plpy.prepare("SELECT CASE WHEN $1 THEN 1 ELSE 0 END AS val", ['boolean'])
rv = plpy.execute(plan, ['fa'], 5) # 'fa' is true in Python rv = plpy.execute(plan, ['fa'], 5) # 'fa' is true in Python
@ -537,7 +537,7 @@ SELECT test_prep_bool_input(); -- 1
CREATE OR REPLACE FUNCTION test_prep_bool_output() RETURNS bool CREATE OR REPLACE FUNCTION test_prep_bool_output() RETURNS bool
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plan = plpy.prepare("SELECT $1 = 1 AS val", ['int']) plan = plpy.prepare("SELECT $1 = 1 AS val", ['int'])
rv = plpy.execute(plan, [0], 5) rv = plpy.execute(plan, [0], 5)
@ -549,7 +549,7 @@ SELECT test_prep_bool_output(); -- false
CREATE OR REPLACE FUNCTION test_prep_bytea_input(bb bytea) RETURNS int CREATE OR REPLACE FUNCTION test_prep_bytea_input(bb bytea) RETURNS int
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plan = plpy.prepare("SELECT octet_length($1) AS val", ['bytea']) plan = plpy.prepare("SELECT octet_length($1) AS val", ['bytea'])
rv = plpy.execute(plan, [bb], 5) rv = plpy.execute(plan, [bb], 5)
@ -560,7 +560,7 @@ SELECT test_prep_bytea_input(E'a\\000b'); -- 3 (embedded null formerly truncated
CREATE OR REPLACE FUNCTION test_prep_bytea_output() RETURNS bytea CREATE OR REPLACE FUNCTION test_prep_bytea_output() RETURNS bytea
LANGUAGE plpythonu LANGUAGE plpython3u
AS $$ AS $$
plan = plpy.prepare("SELECT decode('aa00bb', 'hex') AS val") plan = plpy.prepare("SELECT decode('aa00bb', 'hex') AS val")
rv = plpy.execute(plan, [], 5) rv = plpy.execute(plan, [], 5)

View File

@ -14,28 +14,28 @@ CREATE TABLE unicode_test (
); );
CREATE FUNCTION unicode_return() RETURNS text AS E' CREATE FUNCTION unicode_return() RETURNS text AS E'
return u"\\xA0" return "\\xA0"
' LANGUAGE plpythonu; ' LANGUAGE plpython3u;
CREATE FUNCTION unicode_trigger() RETURNS trigger AS E' CREATE FUNCTION unicode_trigger() RETURNS trigger AS E'
TD["new"]["testvalue"] = u"\\xA0" TD["new"]["testvalue"] = "\\xA0"
return "MODIFY" return "MODIFY"
' LANGUAGE plpythonu; ' LANGUAGE plpython3u;
CREATE TRIGGER unicode_test_bi BEFORE INSERT ON unicode_test CREATE TRIGGER unicode_test_bi BEFORE INSERT ON unicode_test
FOR EACH ROW EXECUTE PROCEDURE unicode_trigger(); FOR EACH ROW EXECUTE PROCEDURE unicode_trigger();
CREATE FUNCTION unicode_plan1() RETURNS text AS E' CREATE FUNCTION unicode_plan1() RETURNS text AS E'
plan = plpy.prepare("SELECT $1 AS testvalue", ["text"]) plan = plpy.prepare("SELECT $1 AS testvalue", ["text"])
rv = plpy.execute(plan, [u"\\xA0"], 1) rv = plpy.execute(plan, ["\\xA0"], 1)
return rv[0]["testvalue"] return rv[0]["testvalue"]
' LANGUAGE plpythonu; ' LANGUAGE plpython3u;
CREATE FUNCTION unicode_plan2() RETURNS text AS E' CREATE FUNCTION unicode_plan2() RETURNS text AS E'
plan = plpy.prepare("SELECT $1 || $2 AS testvalue", ["text", u"text"]) plan = plpy.prepare("SELECT $1 || $2 AS testvalue", ["text", "text"])
rv = plpy.execute(plan, ["foo", "bar"], 1) rv = plpy.execute(plan, ["foo", "bar"], 1)
return rv[0]["testvalue"] return rv[0]["testvalue"]
' LANGUAGE plpythonu; ' LANGUAGE plpython3u;
SELECT unicode_return(); SELECT unicode_return();

View File

@ -4,16 +4,16 @@
CREATE FUNCTION test_void_func1() RETURNS void AS $$ CREATE FUNCTION test_void_func1() RETURNS void AS $$
x = 10 x = 10
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
-- illegal: can't return non-None value in void-returning func -- illegal: can't return non-None value in void-returning func
CREATE FUNCTION test_void_func2() RETURNS void AS $$ CREATE FUNCTION test_void_func2() RETURNS void AS $$
return 10 return 10
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
CREATE FUNCTION test_return_none() RETURNS int AS $$ CREATE FUNCTION test_return_none() RETURNS int AS $$
None None
$$ LANGUAGE plpythonu; $$ LANGUAGE plpython3u;
-- Tests for functions returning void -- Tests for functions returning void

View File

@ -314,55 +314,6 @@ sub taptest
return; return;
} }
sub mangle_plpython3
{
my $tests = shift;
mkdir "results" unless -d "results";
mkdir "sql/python3";
mkdir "results/python3";
mkdir "expected/python3";
foreach my $test (@$tests)
{
local $/ = undef;
foreach my $dir ('sql', 'expected')
{
my $extension = ($dir eq 'sql' ? 'sql' : 'out');
my @files =
glob("$dir/$test.$extension $dir/${test}_[0-9].$extension");
foreach my $file (@files)
{
open(my $handle, '<', $file)
|| die "test file $file not found";
my $contents = <$handle>;
close($handle);
do
{
s/<type 'exceptions\.([[:alpha:]]*)'>/<class '$1'>/g;
s/<type 'long'>/<class 'int'>/g;
s/([0-9][0-9]*)L/$1/g;
s/([ [{])u"/$1"/g;
s/([ [{])u'/$1'/g;
s/def next/def __next__/g;
s/LANGUAGE plpython2?u/LANGUAGE plpython3u/g;
s/EXTENSION (\S*?)plpython2?u/EXTENSION $1plpython3u/g;
s/installing required extension "plpython2u"/installing required extension "plpython3u"/g;
}
for ($contents);
my $base = basename $file;
open($handle, '>', "$dir/python3/$base")
|| die "opening python 3 file for $file";
print $handle $contents;
close($handle);
}
}
}
do { s!^!python3/!; }
foreach (@$tests);
return @$tests;
}
sub plcheck sub plcheck
{ {
chdir "$topdir/src/pl"; chdir "$topdir/src/pl";
@ -386,8 +337,7 @@ sub plcheck
if ($lang eq 'plpython') if ($lang eq 'plpython')
{ {
next next
unless -d "$topdir/$Config/plpython2" unless -d "$topdir/$Config/plpython3";
|| -d "$topdir/$Config/plpython3";
$lang = 'plpythonu'; $lang = 'plpythonu';
} }
else else
@ -397,8 +347,6 @@ sub plcheck
my @lang_args = ("--load-extension=$lang"); my @lang_args = ("--load-extension=$lang");
chdir $dir; chdir $dir;
my @tests = fetchTests(); my @tests = fetchTests();
@tests = mangle_plpython3(\@tests)
if $lang eq 'plpythonu' && -d "$topdir/$Config/plpython3";
if ($lang eq 'plperl') if ($lang eq 'plperl')
{ {
@ -462,28 +410,6 @@ sub subdircheck
my @opts = fetchRegressOpts(); my @opts = fetchRegressOpts();
# Special processing for python transform modules, see their respective
# Makefiles for more details regarding Python-version specific
# dependencies.
if ($module =~ /_plpython$/)
{
die "Python not enabled in configuration"
if !defined($config->{python});
@opts = grep { $_ !~ /plpythonu/ } @opts;
if (-d "$topdir/$Config/plpython2")
{
push @opts, "--load-extension=plpythonu";
push @opts, '--load-extension=' . $module . 'u';
}
else
{
# must be python 3
@tests = mangle_plpython3(\@tests);
}
}
print "============================================================\n"; print "============================================================\n";
print "Checking $module\n"; print "Checking $module\n";
my @args = ( my @args = (