From 8b6010b8350a1756cd85595705971df81b5ffc07 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 3 Jul 2014 16:10:50 -0400 Subject: Improve support for composite types in PL/Python. Allow PL/Python functions to return arrays of composite types. Also, fix the restriction that plpy.prepare/plpy.execute couldn't handle query parameters or result columns of composite types. In passing, adopt a saner arrangement for where to release the tupledesc reference counts acquired via lookup_rowtype_tupdesc. The callers of PLyObject_ToCompositeDatum were doing the lookups, but then the releases happened somewhere down inside subroutines of PLyObject_ToCompositeDatum, which is bizarre and bug-prone. Instead release in the same function that acquires the refcount. Ed Behn and Ronan Dunklau, reviewed by Abhijit Menon-Sen --- src/pl/plpython/expected/plpython_spi.out | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/pl/plpython/expected/plpython_spi.out') diff --git a/src/pl/plpython/expected/plpython_spi.out b/src/pl/plpython/expected/plpython_spi.out index 517579471c9..e2861dfa722 100644 --- a/src/pl/plpython/expected/plpython_spi.out +++ b/src/pl/plpython/expected/plpython_spi.out @@ -376,6 +376,15 @@ plan = plpy.prepare("select fname, lname from users where fname like $1 || '%'", ["text"]) c = plpy.cursor(plan, ["a", "b"]) $$ LANGUAGE plpythonu; +CREATE TYPE test_composite_type AS ( + a1 int, + a2 varchar +); +CREATE OR REPLACE FUNCTION plan_composite_args() RETURNS test_composite_type AS $$ +plan = plpy.prepare("select $1 as c1", ["test_composite_type"]) +res = plpy.execute(plan, [{"a1": 3, "a2": "label"}]) +return res[0]["c1"] +$$ LANGUAGE plpythonu; SELECT simple_cursor_test(); simple_cursor_test -------------------- @@ -432,3 +441,9 @@ CONTEXT: Traceback (most recent call last): PL/Python function "cursor_plan_wrong_args", line 4, in c = plpy.cursor(plan, ["a", "b"]) PL/Python function "cursor_plan_wrong_args" +SELECT plan_composite_args(); + plan_composite_args +--------------------- + (3,label) +(1 row) + -- cgit v1.2.3