1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-12 02:37:31 +03:00

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

@@ -87,3 +87,21 @@ SELECT join_sequences(sequences) FROM sequences
WHERE join_sequences(sequences) ~* '^A';
SELECT join_sequences(sequences) FROM sequences
WHERE join_sequences(sequences) ~* '^B';
--
-- 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();