Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbebe7c5

Browse files
committed
Here's a patch to do the following:
1. Rename spi_return_next to return_next.2. Add a new test for return_next.3. Update the expected output.4. Update the documentation.Abhijit Menon-Sen
1 parent27bdb0c commitbebe7c5

File tree

5 files changed

+55
-57
lines changed

5 files changed

+55
-57
lines changed

‎doc/src/sgml/plperl.sgml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.40 2005/05/20 01:52:24 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.41 2005/06/05 03:16:29 momjian Exp $
33
-->
44

55
<chapter id="plperl">
@@ -182,8 +182,11 @@ $$ LANGUAGE plperl;
182182
SELECT * FROM perl_set();
183183
</programlisting>
184184

185-
Note that when you do this, Perl will have to build the entire array in
186-
memory; therefore the technique does not scale to very large result sets.
185+
When you do this, Perl will have to build the entire array in memory;
186+
therefore the technique does not scale to very large result sets. You
187+
can instead call <function>return_next</function> for each element of
188+
the result set, passing it either a scalar or a reference to a hash,
189+
as appropriate to your function's return type.
187190
</para>
188191

189192
<para>

‎src/pl/plperl/SPI.xs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ spi_spi_exec_query(query, ...)
9898
RETVAL
9999

100100
void
101-
spi_spi_return_next(rv)
101+
spi_return_next(rv)
102102
SV*rv;
103103
CODE:
104104
plperl_return_next(rv);

‎src/pl/plperl/expected/plperl.out

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ CREATE OR REPLACE FUNCTION perl_set_int(int) RETURNS SETOF INTEGER AS $$
4040
return undef;
4141
$$ LANGUAGE plperl;
4242
SELECT 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
4744
SELECT * 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 $$
5350
return [0..$_[0]];
5451
$$ LANGUAGE plperl;
5552
SELECT 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
6654
SELECT * 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;
11199
SELECT perl_set();
112-
perl_set
113-
----------
114-
(0 rows)
115-
100+
ERROR: set-valued function called in context that cannot accept a set
116101
SELECT * 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;
128113
SELECT 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
130115
SELECT * FROM perl_set();
131-
ERROR:elements ofPerlresult arraymustbe reference to hash
116+
ERROR:setof-composite-returningPerlfunctionmustcall return_next with reference to hash
132117
CREATE 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;
139124
SELECT 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
147126
SELECT * 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;
188167
SELECT 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
193169
SELECT * FROM perl_record_set();
194170
ERROR: a column definition list is required for functions returning "record"
195171
SELECT * 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;
207183
SELECT perl_record_set();
208-
ERROR: functionreturning recordcalled in context that cannot accepttype record
184+
ERROR:set-valuedfunction called in context that cannot accepta set
209185
SELECT * FROM perl_record_set();
210186
ERROR: a column definition list is required for functions returning "record"
211187
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
212-
ERROR:elements ofPerlresult arraymustbe reference to hash
188+
ERROR:setof-composite-returningPerlfunctionmustcall return_next with reference to hash
213189
CREATE 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;
220196
SELECT perl_record_set();
221-
ERROR: functionreturning recordcalled in context that cannot accepttype record
197+
ERROR:set-valuedfunction called in context that cannot accepta set
222198
SELECT * FROM perl_record_set();
223199
ERROR: a column definition list is required for functions returning "record"
224200
SELECT * FROM perl_record_set() AS (f1 integer, f2 text, f3 text);
@@ -261,13 +237,7 @@ RETURNS SETOF record AS $$
261237
];
262238
$$ LANGUAGE plperl;
263239
SELECT 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
271241
SELECT * FROM perl_out_params_set();
272242
f1 | f2 | f3
273243
----+-------+------------
@@ -277,13 +247,7 @@ SELECT * FROM perl_out_params_set();
277247
(3 rows)
278248

279249
SELECT (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;
325289
SELECT * 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
327291
CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
328292
return {y => 3, z => 4};
329293
$$ LANGUAGE plperl;
330294
SELECT * 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
332296
CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
333297
return [
334298
[1, 2],
335299
[3, 4]
336300
];
337301
$$ LANGUAGE plperl;
338302
SELECT * FROM foo_set_bad();
339-
ERROR:elements ofPerlresult arraymustbe reference to hash
303+
ERROR:setof-composite-returningPerlfunctionmustcall return_next with reference to hash
340304
CREATE OR REPLACE FUNCTION foo_set_bad() RETURNS SETOF footype AS $$
341305
return [
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+

‎src/pl/plperl/plperl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* ENHANCEMENTS, OR MODIFICATIONS.
3434
*
3535
* IDENTIFICATION
36-
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.75 2005/06/04 20:33:06 momjian Exp $
36+
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.76 2005/06/05 03:16:35 momjian Exp $
3737
*
3838
**********************************************************************/
3939

@@ -222,7 +222,7 @@ plperl_safe_init(void)
222222
"use vars qw($PLContainer); $PLContainer = new Safe('PLPerl');"
223223
"$PLContainer->permit_only(':default');"
224224
"$PLContainer->permit(qw[:base_math !:base_io sort time]);"
225-
"$PLContainer->share(qw[&elog &spi_exec_query &spi_return_next "
225+
"$PLContainer->share(qw[&elog &spi_exec_query &return_next "
226226
"&DEBUG &LOG &INFO &NOTICE &WARNING &ERROR %_SHARED ]);"
227227
;
228228

‎src/pl/plperl/sql/plperl.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,16 @@ $$ LANGUAGE plperl;
234234
SELECT perl_get_field((11,12),'x');
235235
SELECT perl_get_field((11,12),'y');
236236
SELECT perl_get_field((11,12),'z');
237+
238+
--
239+
-- Test return_next
240+
--
241+
242+
CREATE OR REPLACEFUNCTIONperl_srf_rn() RETURNS SETOF RECORDAS $$
243+
$i=0;
244+
for ("World","PostgreSQL","PL/Perl") {
245+
return_next({f1=>++$i, f2=>'Hello', f3=>$_});
246+
}
247+
return;
248+
$$ language plperl;
249+
SELECT*from perl_srf_rn()AS (f1INTEGER, f2TEXT, f3TEXT);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp