diff --git a/src/pl/plpython/expected/plpython_setof.out b/src/pl/plpython/expected/plpython_setof.out index b3bbdd81238c82fd374d1f653a6ea50284dfe851..62b8a454a35dfd199f00e3a69697931f1d2a2a92 100644 --- a/src/pl/plpython/expected/plpython_setof.out +++ b/src/pl/plpython/expected/plpython_setof.out @@ -124,8 +124,7 @@ SELECT test_setof_spi_in_iterator(); World (4 rows) --- setof function with an SPI result set (used to crash because of --- memory management issues across multiple calls) +-- returns set of named-composite-type tuples CREATE OR REPLACE FUNCTION get_user_records() RETURNS SETOF users AS $$ @@ -140,3 +139,36 @@ SELECT get_user_records(); (willem,doe,w_doe,3) (4 rows) +SELECT * FROM get_user_records(); + fname | lname | username | userid +--------+-------+----------+-------- + jane | doe | j_doe | 1 + john | doe | johnd | 2 + rick | smith | slash | 4 + willem | doe | w_doe | 3 +(4 rows) + +-- same, but returning set of RECORD +CREATE OR REPLACE FUNCTION get_user_records2() +RETURNS TABLE(fname text, lname text, username text, userid int) +AS $$ + return plpy.execute("SELECT * FROM users ORDER BY username") +$$ LANGUAGE plpythonu; +SELECT get_user_records2(); + get_user_records2 +---------------------- + (jane,doe,j_doe,1) + (john,doe,johnd,2) + (rick,smith,slash,4) + (willem,doe,w_doe,3) +(4 rows) + +SELECT * FROM get_user_records2(); + fname | lname | username | userid +--------+-------+----------+-------- + jane | doe | j_doe | 1 + john | doe | johnd | 2 + rick | smith | slash | 4 + willem | doe | w_doe | 3 +(4 rows) + diff --git a/src/pl/plpython/sql/plpython_setof.sql b/src/pl/plpython/sql/plpython_setof.sql index 243f711dcc60dd8f9f005b25d406157c11ee620e..fe034fba45efe73c6ac1b0fc5f6d2692a5a22c45 100644 --- a/src/pl/plpython/sql/plpython_setof.sql +++ b/src/pl/plpython/sql/plpython_setof.sql @@ -64,9 +64,7 @@ SELECT test_setof_as_iterator(2, null); SELECT test_setof_spi_in_iterator(); --- setof function with an SPI result set (used to crash because of --- memory management issues across multiple calls) - +-- returns set of named-composite-type tuples CREATE OR REPLACE FUNCTION get_user_records() RETURNS SETOF users AS $$ @@ -74,3 +72,14 @@ AS $$ $$ LANGUAGE plpythonu; SELECT get_user_records(); +SELECT * FROM get_user_records(); + +-- same, but returning set of RECORD +CREATE OR REPLACE FUNCTION get_user_records2() +RETURNS TABLE(fname text, lname text, username text, userid int) +AS $$ + return plpy.execute("SELECT * FROM users ORDER BY username") +$$ LANGUAGE plpythonu; + +SELECT get_user_records2(); +SELECT * FROM get_user_records2();