mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-18 04:17:00 +08: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:
@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user