mirror of
https://github.com/postgres/postgres.git
synced 2025-12-12 02:37:31 +03:00
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
This commit is contained in:
@@ -125,7 +125,7 @@ SELECT * FROM changing_test();
|
||||
ALTER TABLE changing ADD COLUMN j integer;
|
||||
SELECT * FROM changing_test();
|
||||
|
||||
-- tables of composite types (not yet implemented)
|
||||
-- tables of composite types
|
||||
|
||||
CREATE FUNCTION composite_types_table(OUT tab table_record[], OUT typ type_record[] ) RETURNS SETOF record AS $$
|
||||
yield {'tab': [['first', 1], ['second', 2]],
|
||||
|
||||
@@ -284,6 +284,17 @@ plan = plpy.prepare("select fname, lname from users where fname like $1 || '%'",
|
||||
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();
|
||||
SELECT double_cursor_close();
|
||||
SELECT cursor_fetch();
|
||||
@@ -293,3 +304,4 @@ SELECT next_after_close();
|
||||
SELECT cursor_fetch_next_empty();
|
||||
SELECT cursor_plan();
|
||||
SELECT cursor_plan_wrong_args();
|
||||
SELECT plan_composite_args();
|
||||
|
||||
@@ -269,7 +269,7 @@ SELECT * FROM test_type_conversion_array_mixed2();
|
||||
|
||||
|
||||
CREATE FUNCTION test_type_conversion_array_record() RETURNS type_record[] AS $$
|
||||
return [None]
|
||||
return [{'first': 'one', 'second': 42}, {'first': 'two', 'second': 11}]
|
||||
$$ LANGUAGE plpythonu;
|
||||
|
||||
SELECT * FROM test_type_conversion_array_record();
|
||||
|
||||
Reference in New Issue
Block a user