Skip to content

Commit 6bff0e7

Browse files
committed
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.
1 parent cf589c9 commit 6bff0e7

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

src/pl/plpython/expected/plpython_setof.out

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ SELECT test_setof_spi_in_iterator();
124124
World
125125
(4 rows)
126126

127-
-- setof function with an SPI result set (used to crash because of
128-
-- memory management issues across multiple calls)
127+
-- returns set of named-composite-type tuples
129128
CREATE OR REPLACE FUNCTION get_user_records()
130129
RETURNS SETOF users
131130
AS $$
@@ -140,3 +139,36 @@ SELECT get_user_records();
140139
(willem,doe,w_doe,3)
141140
(4 rows)
142141

142+
SELECT * FROM get_user_records();
143+
fname | lname | username | userid
144+
--------+-------+----------+--------
145+
jane | doe | j_doe | 1
146+
john | doe | johnd | 2
147+
rick | smith | slash | 4
148+
willem | doe | w_doe | 3
149+
(4 rows)
150+
151+
-- same, but returning set of RECORD
152+
CREATE OR REPLACE FUNCTION get_user_records2()
153+
RETURNS TABLE(fname text, lname text, username text, userid int)
154+
AS $$
155+
return plpy.execute("SELECT * FROM users ORDER BY username")
156+
$$ LANGUAGE plpythonu;
157+
SELECT get_user_records2();
158+
get_user_records2
159+
----------------------
160+
(jane,doe,j_doe,1)
161+
(john,doe,johnd,2)
162+
(rick,smith,slash,4)
163+
(willem,doe,w_doe,3)
164+
(4 rows)
165+
166+
SELECT * FROM get_user_records2();
167+
fname | lname | username | userid
168+
--------+-------+----------+--------
169+
jane | doe | j_doe | 1
170+
john | doe | johnd | 2
171+
rick | smith | slash | 4
172+
willem | doe | w_doe | 3
173+
(4 rows)
174+

src/pl/plpython/sql/plpython_setof.sql

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,22 @@ SELECT test_setof_as_iterator(2, null);
6464
SELECT test_setof_spi_in_iterator();
6565

6666

67-
-- setof function with an SPI result set (used to crash because of
68-
-- memory management issues across multiple calls)
69-
67+
-- returns set of named-composite-type tuples
7068
CREATE OR REPLACE FUNCTION get_user_records()
7169
RETURNS SETOF users
7270
AS $$
7371
return plpy.execute("SELECT * FROM users ORDER BY username")
7472
$$ LANGUAGE plpythonu;
7573

7674
SELECT get_user_records();
75+
SELECT * FROM get_user_records();
76+
77+
-- same, but returning set of RECORD
78+
CREATE OR REPLACE FUNCTION get_user_records2()
79+
RETURNS TABLE(fname text, lname text, username text, userid int)
80+
AS $$
81+
return plpy.execute("SELECT * FROM users ORDER BY username")
82+
$$ LANGUAGE plpythonu;
83+
84+
SELECT get_user_records2();
85+
SELECT * FROM get_user_records2();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy