Re: Unexpected plperl difference between 8.4 and 9.1 - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Unexpected plperl difference between 8.4 and 9.1
Date
Msg-id 1345479089-sup-5619@alvh.no-ip.org
Whole thread Raw
In response to Re: Unexpected plperl difference between 8.4 and 9.1  (Alex Hunsaker <badalex@gmail.com>)
Responses Re: Unexpected plperl difference between 8.4 and 9.1
Re: Unexpected plperl difference between 8.4 and 9.1
List pgsql-hackers
Excerpts from Alex Hunsaker's message of lun ago 20 12:03:11 -0400 2012:
> On Sun, Aug 19, 2012 at 2:26 PM, Joel Jacobson <joel@trustly.com> wrote:
>
> > 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.
> >
> >
> Hrm seems to work for me. What version of perl is this?
> $ perl -V
> Summary of my perl5 (revision 5 version 16 subversion 0) configuration:
> [snip]
> Characteristics of this binary (from libperl):
>   Compile-time options: HAS_TIMES MYMALLOC PERLIO_LAYERS
>                         PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP
>                         PERL_PRESERVE_IVUV USE_64_BIT_ALL USE_64_BIT_INT
>                         USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE
>                         USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_PERLIO
>                         USE_PERL_ATOF

I can reproduce the failure with 5.14.2

alvherre=# CREATE OR REPLACE FUNCTION test1() RETURNS SETOF NUMERIC AS $BODY$
alvherre$# use strict;
alvherre$# use warnings;
alvherre$# for(my $i=0 ; $i<10; $i++) {
alvherre$# my $rand = rand();
alvherre$# $rand =~ m/(.*)/;
alvherre$# return_next($1);
alvherre$# }
alvherre$# return;
alvherre$# $BODY$ LANGUAGE plperl;
CREATE FUNCTION
alvherre=# select * from test1();      test1

-------------------0.3960883115223660.3960883115223660.3960883115223660.3960883115223660.3960883115223660.3960883115223660.3960883115223660.3960883115223660.3960883115223660.396088311522366
(10 filas)

It works fine if I assign $1 to another variable before return_next'ing
it:

alvherre=# 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/(.*)/;
my $a=$1; return_next($a);
}
return;
$BODY$ LANGUAGE plperl;
CREATE FUNCTION
alvherre=# select * from test1();      test1
-------------------0.6935694844733040.7575898390236660.4772338974672830.5729637014182530.189924114046409
0.201557730077170.6244523219268920.1341350865960390.4176066385029210.95250325772281 
(10 filas)

(In short, same as Joel).

--
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services



pgsql-hackers by date:

Previous
From: Fujii Masao
Date:
Subject: Re: bug of pg_trgm?
Next
From: Heikki Linnakangas
Date:
Subject: Re: New WAL code dumps core trivially on replay of bad data