*** src/pl/plperl/SPI.xs~ 2005-06-05 06:25:09.673611157 +0530
--- src/pl/plperl/SPI.xs 2005-06-05 07:45:40.183864013 +0530
***************
*** 98,104 ****
RETVAL
void
! spi_spi_return_next(rv)
SV *rv;
CODE:
plperl_return_next(rv);
--- 98,104 ----
RETVAL
void
! spi_return_next(rv)
SV *rv;
CODE:
plperl_return_next(rv);
*** src/pl/plperl/plperl.c~ 2005-06-05 06:25:04.760469337 +0530
--- src/pl/plperl/plperl.c 2005-06-05 07:45:02.496446890 +0530
***************
*** 222,228 ****
"use vars qw($PLContainer); $PLContainer = new Safe('PLPerl');"
"$PLContainer->permit_only(':default');"
"$PLContainer->permit(qw[:base_math !:base_io sort time]);"
! "$PLContainer->share(qw[&elog &spi_exec_query &spi_return_next "
"&DEBUG &LOG &INFO &NOTICE &WARNING &ERROR %_SHARED ]);"
;
--- 222,228 ----
"use vars qw($PLContainer); $PLContainer = new Safe('PLPerl');"
"$PLContainer->permit_only(':default');"
"$PLContainer->permit(qw[:base_math !:base_io sort time]);"
! "$PLContainer->share(qw[&elog &spi_exec_query &return_next "
"&DEBUG &LOG &INFO &NOTICE &WARNING &ERROR %_SHARED ]);"
;
*** src/pl/plperl/sql/plperl.sql~ 2005-06-05 06:25:17.113311662 +0530
--- src/pl/plperl/sql/plperl.sql 2005-06-05 07:50:31.740937624 +0530
***************
*** 234,236 ****
--- 234,249 ----
SELECT perl_get_field((11,12), 'x');
SELECT perl_get_field((11,12), 'y');
SELECT perl_get_field((11,12), 'z');
+
+ --
+ -- Test return_next
+ --
+
+ CREATE OR REPLACE FUNCTION perl_srf_rn() RETURNS SETOF RECORD AS $$
+ $i = 0;
+ for ("World", "PostgreSQL", "PL/Perl") {
+ return_next({f1=>++$i, f2=>'Hello', f3=>$_});
+ }
+ return;
+ $$ language plperl;
+ SELECT * from perl_srf_rn() AS (f1 INTEGER, f2 TEXT, f3 TEXT);
*** src/pl/plperl/expected/plperl.out~ 2005-06-05 06:25:24.928946502 +0530
--- src/pl/plperl/expected/plperl.out 2005-06-05 07:53:31.810484804 +0530
***************
*** 40,49 ****
return undef;
$$ LANGUAGE plperl;
SELECT perl_set_int(5);
! perl_set_int
! --------------
! (0 rows)
!
SELECT * FROM perl_set_int(5);
perl_set_int
--------------
--- 40,46 ----
return undef;
$$ LANGUAGE plperl;
SELECT perl_set_int(5);
! ERROR: set-valued function called in context that cannot accept a set
SELECT * FROM perl_set_int(5);
perl_set_int
--------------
***************
*** 53,68 ****
return [0..$_[0]];
$$ LANGUAGE plperl;
SELECT perl_set_int(5);
! perl_set_int
! --------------
! 0
! 1
! 2
! 3
! 4
! 5
! (6 rows)
!
SELECT * FROM perl_set_int(5);
perl_set_int
--------------
--- 50,56 ----
return [0..$_[0]];
$$ LANGUAGE plperl;
SELECT perl_set_int(5);
! ERROR: set-valued function called in context that cannot accept a set
SELECT * FROM perl_set_int(5);
perl_set_int
--------------
***************
*** 109,118 ****
return undef;
$$ LANGUAGE plperl;
SELECT perl_set();
! perl_set
! ----------
! (0 rows)
!
SELECT * FROM perl_set();
f1 | f2 | f3
----+----+----
--- 97,103 ----
return undef;
$$ LANGUAGE plperl;
SELECT perl_set();
! ERROR: set-valued function called in context that cannot accept a set
SELECT * FROM perl_set();
f1 | f2 | f3
----+----+----
***************
*** 126,134 ****
];
$$ LANGUAGE plperl;
SELECT perl_set();
! ERROR: elements of Perl result array must be reference to hash
SELECT * FROM perl_set();
! ERROR: elements of Perl result array must be reference to hash
CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
return [
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
--- 111,119 ----
];
$$ LANGUAGE plperl;
SELECT perl_set();
! ERROR: set-valued function called in context that cannot accept a set
SELECT * FROM perl_set();
! ERROR: setof-composite-returning Perl function must call return_next with reference to hash
CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testrowperl AS $$
return [
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
***************
*** 137,149 ****
];
$$ LANGUAGE plperl;
SELECT perl_set();
! perl_set
! ----------------------
! (1,Hello,World)
! (2,Hello,PostgreSQL)
! (3,Hello,PL/Perl)
! (3 rows)
!
SELECT * FROM perl_set();
f1 | f2 | f3
----+-------+------------
--- 122,128 ----
];
$$ LANGUAGE plperl;
SELECT perl_set();
! ERROR: set-valued function called in context that cannot accept a set
SELECT * FROM perl_set();
f1 | f2 | f3
----+-------+------------
***************
*** 186,195 ****
return undef;
$$ LANGUAGE plperl;
SELECT perl_record_set();
! perl_record_set
! -----------------
! (0 rows)
!
SELECT * FROM perl_record_set();
ERROR: a column definition list is required for functions returning "record"
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
--- 165,171 ----
return undef;
$$ LANGUAGE plperl;
SELECT perl_record_set();
! ERROR: set-valued function called in context that cannot accept a set
SELECT * FROM perl_record_set();
ERROR: a column definition list is required for functions returning "record"
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
***************
*** 205,215 ****
];
$$ LANGUAGE plperl;
SELECT perl_record_set();
! ERROR: function returning record called in context that cannot accept type record
SELECT * FROM perl_record_set();
ERROR: a column definition list is required for functions returning "record"
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
! ERROR: elements of Perl result array must be reference to hash
CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
return [
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
--- 181,191 ----
];
$$ LANGUAGE plperl;
SELECT perl_record_set();
! ERROR: set-valued function called in context that cannot accept a set
SELECT * FROM perl_record_set();
ERROR: a column definition list is required for functions returning "record"
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
! ERROR: setof-composite-returning Perl function must call return_next with reference to hash
CREATE OR REPLACE FUNCTION perl_record_set() RETURNS SETOF record AS $$
return [
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
***************
*** 218,224 ****
];
$$ LANGUAGE plperl;
SELECT perl_record_set();
! ERROR: function returning record called in context that cannot accept type record
SELECT * FROM perl_record_set();
ERROR: a column definition list is required for functions returning "record"
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
--- 194,200 ----
];
$$ LANGUAGE plperl;
SELECT perl_record_set();
! ERROR: set-valued function called in context that cannot accept a set
SELECT * FROM perl_record_set();
ERROR: a column definition list is required for functions returning "record"
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
***************
*** 261,273 ****
];
$$ LANGUAGE plperl;
SELECT perl_out_params_set();
! perl_out_params_set
! ----------------------
! (1,Hello,World)
! (2,Hello,PostgreSQL)
! (3,Hello,PL/Perl)
! (3 rows)
!
SELECT * FROM perl_out_params_set();
f1 | f2 | f3
----+-------+------------
--- 237,243 ----
];
$$ LANGUAGE plperl;
SELECT perl_out_params_set();
! ERROR: set-valued function called in context that cannot accept a set
SELECT * FROM perl_out_params_set();
f1 | f2 | f3
----+-------+------------
***************
*** 277,289 ****
(3 rows)
SELECT (perl_out_params_set()).f3;
! f3
! ------------
! World
! PostgreSQL
! PL/Perl
! (3 rows)
!
--
-- Check behavior with erroneous return values
--
--- 247,253 ----
(3 rows)
SELECT (perl_out_params_set()).f3;
! ERROR: set-valued function called in context that cannot accept a set
--
-- Check behavior with erroneous return values
--
***************
*** 323,334 ****
return 42;
$$ LANGUAGE plperl;
SELECT * FROM foo_set_bad();
! ERROR: set-returning Perl function must return reference to array
CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
return {y => 3, z => 4};
$$ LANGUAGE plperl;
SELECT * FROM foo_set_bad();
! ERROR: set-returning Perl function must return reference to array
CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
return [
[1, 2],
--- 287,298 ----
return 42;
$$ LANGUAGE plperl;
SELECT * FROM foo_set_bad();
! ERROR: set-returning Perl function must return reference to array or use return_next
CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
return {y => 3, z => 4};
$$ LANGUAGE plperl;
SELECT * FROM foo_set_bad();
! ERROR: set-returning Perl function must return reference to array or use return_next
CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
return [
[1, 2],
***************
*** 336,342 ****
];
$$ LANGUAGE plperl;
SELECT * FROM foo_set_bad();
! ERROR: elements of Perl result array must be reference to hash
CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
return [
{y => 3, z => 4}
--- 300,306 ----
];
$$ LANGUAGE plperl;
SELECT * FROM foo_set_bad();
! ERROR: setof-composite-returning Perl function must call return_next with reference to hash
CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
return [
{y => 3, z => 4}
***************
*** 368,370 ****
--- 332,352 ----
(1 row)
+ --
+ -- Test return_next
+ --
+ CREATE OR REPLACE FUNCTION perl_srf_rn() RETURNS SETOF RECORD AS $$
+ $i = 0;
+ for ("World", "PostgreSQL", "PL/Perl") {
+ return_next({f1=>++$i, f2=>'Hello', f3=>$_});
+ }
+ return;
+ $$ language plperl;
+ SELECT * from perl_srf_rn() AS (f1 INTEGER, f2 TEXT, f3 TEXT);
+ f1 | f2 | f3
+ ----+-------+------------
+ 1 | Hello | World
+ 2 | Hello | PostgreSQL
+ 3 | Hello | PL/Perl
+ (3 rows)
+
*** doc/src/sgml/plperl.sgml~ 2005-06-05 07:58:46.325548333 +0530
--- doc/src/sgml/plperl.sgml 2005-06-05 08:03:06.139166586 +0530
***************
*** 182,189 ****
SELECT * FROM perl_set();
! Note that when you do this, Perl will have to build the entire array in
! memory; therefore the technique does not scale to very large result sets.
--- 182,192 ----
SELECT * FROM perl_set();
! When you do this, Perl will have to build the entire array in memory;
! therefore the technique does not scale to very large result sets. You
! can instead call return_next for each element of
! the result set, passing it either a scalar or a reference to a hash,
! as appropriate to your function's return type.