From bc411f25c14f65b459de5dbc96ac79e7741ef9ee Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Sat, 26 Feb 2011 16:53:11 +0200 Subject: Table function support for PL/Python MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows functions with multiple OUT parameters returning both one or multiple records (RECORD or SETOF RECORD). Jan UrbaƄski, reviewed by Hitoshi Harada --- doc/src/sgml/plpython.sgml | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/plpython.sgml b/doc/src/sgml/plpython.sgml index 7c869a8719f..94d42bfaaa1 100644 --- a/doc/src/sgml/plpython.sgml +++ b/doc/src/sgml/plpython.sgml @@ -390,18 +390,6 @@ $$ LANGUAGE plpythonu; return type and the Python data type of the actual return object are not flagged; the value will be converted in any case. - - - - PL/Python functions cannot return - either type RECORD or SETOF RECORD. A - workaround is to write a PL/pgSQL - function that creates a temporary table, have it call the - PL/Python function to fill the table, - and then have the PL/pgSQL function - return the generic RECORD from the temporary table. - - @@ -593,6 +581,17 @@ $$ LANGUAGE plpythonu; + + + Functions with OUT parameters are also supported. For example: + +CREATE FUNCTION multiout_simple(OUT i integer, OUT j integer) AS $$ +return (1, 2) +$$ LANGUAGE plpythonu; + +SELECT * FROM multiout_simple(); + + @@ -692,6 +691,19 @@ $$ LANGUAGE plpythonu; + + + Set-returning functions with OUT parameters + (using RETURNS SETOF record) are also + supported. For example: + +CREATE FUNCTION multiout_simple_setof(n integer, OUT integer, OUT integer) RETURNS SETOF record AS $$ +return [(1, 2)] * n +$$ LANGUAGE plpythonu; + +SELECT * FROM multiout_simple_setof(3); + + -- cgit v1.2.3