Use generic attribute management in PL/Python

Switch the implementation of the plan and result types to generic attribute
management, as described at <http://docs.python.org/extending/newtypes.html>.
This modernizes and simplifies the code a bit and prepares for Python 3.1,
where the old way doesn't work anymore.
This commit is contained in:
Peter Eisentraut
2009-08-25 08:14:42 +00:00
parent 5dff93638c
commit 983d10833e
3 changed files with 67 additions and 28 deletions

View File

@ -111,3 +111,24 @@ SELECT join_sequences(sequences) FROM sequences
----------------
(0 rows)
--
-- plan and result objects
--
CREATE FUNCTION result_nrows_test() RETURNS int
AS $$
plan = plpy.prepare("SELECT 1 UNION SELECT 2")
plpy.info(plan.status()) # not really documented or useful
result = plpy.execute(plan)
if result.status() > 0:
return result.nrows()
else:
return None
$$ LANGUAGE plpythonu;
SELECT result_nrows_test();
INFO: (True,)
CONTEXT: PL/Python function "result_nrows_test"
result_nrows_test
-------------------
2
(1 row)