Add a regression test case for plpython function returning setof RECORD.
We had coverage for functions returning setof a named composite type, but not for anonymous records, which is a somewhat different code path. In view of recent crash report from Sergey Konoplev, this seems worth testing, though I doubt there's any deterministic bug here today.
This commit is contained in:
parent
cf589c9c1f
commit
6bff0e7d92
@ -124,8 +124,7 @@ SELECT test_setof_spi_in_iterator();
|
|||||||
World
|
World
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
-- setof function with an SPI result set (used to crash because of
|
-- returns set of named-composite-type tuples
|
||||||
-- memory management issues across multiple calls)
|
|
||||||
CREATE OR REPLACE FUNCTION get_user_records()
|
CREATE OR REPLACE FUNCTION get_user_records()
|
||||||
RETURNS SETOF users
|
RETURNS SETOF users
|
||||||
AS $$
|
AS $$
|
||||||
@ -140,3 +139,36 @@ SELECT get_user_records();
|
|||||||
(willem,doe,w_doe,3)
|
(willem,doe,w_doe,3)
|
||||||
(4 rows)
|
(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)
|
||||||
|
|
||||||
|
@ -64,9 +64,7 @@ SELECT test_setof_as_iterator(2, null);
|
|||||||
SELECT test_setof_spi_in_iterator();
|
SELECT test_setof_spi_in_iterator();
|
||||||
|
|
||||||
|
|
||||||
-- setof function with an SPI result set (used to crash because of
|
-- returns set of named-composite-type tuples
|
||||||
-- memory management issues across multiple calls)
|
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION get_user_records()
|
CREATE OR REPLACE FUNCTION get_user_records()
|
||||||
RETURNS SETOF users
|
RETURNS SETOF users
|
||||||
AS $$
|
AS $$
|
||||||
@ -74,3 +72,14 @@ AS $$
|
|||||||
$$ LANGUAGE plpythonu;
|
$$ LANGUAGE plpythonu;
|
||||||
|
|
||||||
SELECT get_user_records();
|
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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user