Unexpected plperl difference between 8.4 and 9.1
От | Joel Jacobson |
---|---|
Тема | Unexpected plperl difference between 8.4 and 9.1 |
Дата | |
Msg-id | CAASwCXeKXc761U9oF3qqgv9wEn8cbCOyzNnNs_f37t6Z2LWBMQ@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Unexpected plperl difference between 8.4 and 9.1
|
Список | pgsql-hackers |
After upgrading from 8.4 to 9.1, one of my plperl functions stopped working properly.
For some reason, when matching a string using a regex, the $1 variable
cannot be returned directly using return_next() but must be
set to a variable first.
If returned directly, it appears to be cached in some strange way,
returning the same value for all 10 rows in the example below.
In 8.4, these two functions returns the same thing, 10 rows of random numbers.
Is this a feature or a bug?
CREATE OR REPLACE FUNCTION test1() RETURNS SETOF NUMERIC AS $BODY$
use strict;
use warnings;
for(my $i=0 ; $i<10; $i++) {
my $rand = rand();
$rand =~ m/(.*)/;
return_next($1);
}
return;
$BODY$ LANGUAGE plperl;
joel=# select * from test1();
0.482287904847535
0.482287904847535
0.482287904847535
0.482287904847535
0.482287904847535
0.482287904847535
0.482287904847535
0.482287904847535
0.482287904847535
0.482287904847535
(10 rows)
CREATE OR REPLACE FUNCTION test2() RETURNS SETOF NUMERIC AS $BODY$
use strict;
use warnings;
for(my $i=0 ; $i<10; $i++) {
my $rand = rand();
$rand =~ m/(.*)/;
my $val = $1;
return_next($val);
}
return;
$BODY$ LANGUAGE plperl;
joel=# select * from test2();
test2
--------------------
0.504361211998972
0.015757483449562
0.154422531777254
0.383329383899088
0.578318997407354
0.0022126436077059
0.970868502733449
0.465566753133679
0.215372148522395
0.390036490131536
(10 rows)
В списке pgsql-hackers по дате отправления: