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

From Alex Hunsaker
Subject Re: Unexpected plperl difference between 8.4 and 9.1
Date
Msg-id CAFaPBrTw8wAE0jJCXOFQcOADJ9wgBwYLKKrqp6dbC9Giu1UnXA@mail.gmail.com
Whole thread Raw
In response to Unexpected plperl difference between 8.4 and 9.1  (Joel Jacobson <joel@trustly.com>)
Responses Re: Unexpected plperl difference between 8.4 and 9.1
List pgsql-hackers


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
$!psql
baroque=> SELECT version();
                                                 version                                                 
---------------------------------------------------------------------------------------------------------
 PostgreSQL 9.1.5 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.7.1 20120721 (prerelease), 64-bit
(1 row)

baroque=> CREATE OR REPLACE FUNCTION test1() RETURNS SETOF NUMERIC AS $BODY$
baroque$> use strict;
baroque$> use warnings;
baroque$> for(my $i=0 ; $i<10; $i++) {
baroque$> my $rand = rand();
baroque$> $rand =~ m/(.*)/;
baroque$> return_next($1);
baroque$> }
baroque$> return;
baroque$> $BODY$ LANGUAGE plperl;
CREATE FUNCTION
baroque=> 
baroque=> select * from test1();
       test1       
-------------------
 0.284491935120062
 0.213769321886019
 0.758221121077565
 0.810816779589864
 0.649781285447791
 0.630792307420037
  0.17897035660857
 0.876314955338863
 0.899575315174307
 0.225134707347706
(10 rows)


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Primary Key Constraint on inheritance table not getting route to child tables
Next
From: Alvaro Herrera
Date:
Subject: Re: The pgrminclude problem