@@ -40,10 +40,7 @@ CREATE OR REPLACE FUNCTION perl_set_int(int) RETURNS SETOF INTEGER AS $$
4040return undef;
4141$$ LANGUAGE plperl;
4242SELECT perl_set_int(5);
43- perl_set_int
44- --------------
45- (0 rows)
46-
43+ ERROR: set-valued function called in context that cannot accept a set
4744SELECT * FROM perl_set_int(5);
4845 perl_set_int
4946--------------
@@ -53,16 +50,7 @@ CREATE OR REPLACE FUNCTION perl_set_int(int) RETURNS SETOF INTEGER AS $$
5350return [0..$_[0]];
5451$$ LANGUAGE plperl;
5552SELECT perl_set_int(5);
56- perl_set_int
57- --------------
58- 0
59- 1
60- 2
61- 3
62- 4
63- 5
64- (6 rows)
65-
53+ ERROR: set-valued function called in context that cannot accept a set
6654SELECT * FROM perl_set_int(5);
6755 perl_set_int
6856--------------
@@ -109,10 +97,7 @@ CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
10997 return undef;
11098$$ LANGUAGE plperl;
11199SELECT perl_set();
112- perl_set
113- ----------
114- (0 rows)
115-
100+ ERROR: set-valued function called in context that cannot accept a set
116101SELECT * FROM perl_set();
117102 f1 | f2 | f3
118103----+----+----
@@ -126,9 +111,9 @@ CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
126111 ];
127112$$ LANGUAGE plperl;
128113SELECT perl_set();
129- ERROR:elements of Perl result array must be reference to hash
114+ ERROR:set-valued function called in context that cannot accept a set
130115SELECT * FROM perl_set();
131- ERROR:elements of Perlresult array mustbe reference to hash
116+ ERROR:setof-composite-returning Perlfunction mustcall return_next with reference to hash
132117CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
133118 return [
134119 { f1 => 1, f2 => 'Hello', f3 => 'World' },
@@ -137,13 +122,7 @@ CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
137122 ];
138123$$ LANGUAGE plperl;
139124SELECT perl_set();
140- perl_set
141- ----------------------
142- (1,Hello,World)
143- (2,Hello,PostgreSQL)
144- (3,Hello,PL/Perl)
145- (3 rows)
146-
125+ ERROR: set-valued function called in context that cannot accept a set
147126SELECT * FROM perl_set();
148127 f1 | f2 | f3
149128----+-------+------------
@@ -186,10 +165,7 @@ CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
186165 return undef;
187166$$ LANGUAGE plperl;
188167SELECT perl_record_set();
189- perl_record_set
190- -----------------
191- (0 rows)
192-
168+ ERROR: set-valued function called in context that cannot accept a set
193169SELECT * FROM perl_record_set();
194170ERROR: a column definition list is required for functions returning "record"
195171SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
@@ -205,11 +181,11 @@ CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
205181 ];
206182$$ LANGUAGE plperl;
207183SELECT perl_record_set();
208- ERROR: functionreturning record called in context that cannot accepttype record
184+ ERROR:set-valued function called in context that cannot accepta set
209185SELECT * FROM perl_record_set();
210186ERROR: a column definition list is required for functions returning "record"
211187SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
212- ERROR:elements of Perlresult array mustbe reference to hash
188+ ERROR:setof-composite-returning Perlfunction mustcall return_next with reference to hash
213189CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
214190 return [
215191 { f1 => 1, f2 => 'Hello', f3 => 'World' },
@@ -218,7 +194,7 @@ CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
218194 ];
219195$$ LANGUAGE plperl;
220196SELECT perl_record_set();
221- ERROR: functionreturning record called in context that cannot accepttype record
197+ ERROR:set-valued function called in context that cannot accepta set
222198SELECT * FROM perl_record_set();
223199ERROR: a column definition list is required for functions returning "record"
224200SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
@@ -261,13 +237,7 @@ RETURNS SETOF record AS $$
261237 ];
262238$$ LANGUAGE plperl;
263239SELECT perl_out_params_set();
264- perl_out_params_set
265- ----------------------
266- (1,Hello,World)
267- (2,Hello,PostgreSQL)
268- (3,Hello,PL/Perl)
269- (3 rows)
270-
240+ ERROR: set-valued function called in context that cannot accept a set
271241SELECT * FROM perl_out_params_set();
272242 f1 | f2 | f3
273243----+-------+------------
@@ -277,13 +247,7 @@ SELECT * FROM perl_out_params_set();
277247(3 rows)
278248
279249SELECT (perl_out_params_set()).f3;
280- f3
281- ------------
282- World
283- PostgreSQL
284- PL/Perl
285- (3 rows)
286-
250+ ERROR: set-valued function called in context that cannot accept a set
287251--
288252-- Check behavior with erroneous return values
289253--
@@ -323,20 +287,20 @@ CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
323287 return 42;
324288$$ LANGUAGE plperl;
325289SELECT * FROM foo_set_bad();
326- ERROR: set-returning Perl function must return reference to array
290+ ERROR: set-returning Perl function must return reference to array or use return_next
327291CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
328292 return {y => 3, z => 4};
329293$$ LANGUAGE plperl;
330294SELECT * FROM foo_set_bad();
331- ERROR: set-returning Perl function must return reference to array
295+ ERROR: set-returning Perl function must return reference to array or use return_next
332296CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
333297return [
334298 [1, 2],
335299 [3, 4]
336300];
337301$$ LANGUAGE plperl;
338302SELECT * FROM foo_set_bad();
339- ERROR:elements of Perlresult array mustbe reference to hash
303+ ERROR:setof-composite-returning Perlfunction mustcall return_next with reference to hash
340304CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
341305return [
342306 {y => 3, z => 4}
@@ -368,3 +332,21 @@ SELECT perl_get_field((11,12), 'z');
368332
369333(1 row)
370334
335+ --
336+ -- Test return_next
337+ --
338+ CREATE OR REPLACE FUNCTION perl_srf_rn() RETURNS SETOF RECORD AS $$
339+ $i = 0;
340+ for ("World", "PostgreSQL", "PL/Perl") {
341+ return_next({f1=>++$i, f2=>'Hello', f3=>$_});
342+ }
343+ return;
344+ $$ language plperl;
345+ SELECT * from perl_srf_rn() AS (f1 INTEGER, f2 TEXT, f3 TEXT);
346+ f1 | f2 | f3
347+ ----+-------+------------
348+ 1 | Hello | World
349+ 2 | Hello | PostgreSQL
350+ 3 | Hello | PL/Perl
351+ (3 rows)
352+