Plperl and my() lexical variables bug?

From: "Philippe Lang" <philippe(dot)lang(at)attiksystem(dot)ch>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Plperl and my() lexical variables bug?
Date: 2006-06-23 09:33:42
Message-ID: 6C0CF58A187DA5479245E0830AF84F421D0E5C@poweredge.attiksystem.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I have something strange here, with Postgresql 8.1.4 under Linux ES 4, installed from the PG Group binaries:

If I run this script:

----------------
CREATE OR REPLACE FUNCTION foo() RETURNS void
AS
$$
my $val;

sub init
{
$val = @_[0];
elog(NOTICE, "1: @_[0]\n");
}

&init(12);
elog(NOTICE, "2: $val\n");
$$
LANGUAGE 'plperl';

select * from foo();
----------------

I get in return something correct:

----------------
NOTICE: 1: 12

NOTICE: 2: 12

Total query runtime: 63 ms.
Data retrieval runtime: 62 ms.
1 rows retrieved.
----------------

But then, if I simply call the function, with:

----------------
select * from foo();
----------------

I get:

----------------
NOTICE: 1: 12

NOTICE: 2:

Total query runtime: 63 ms.
Data retrieval runtime: 62 ms.
1 rows retrieved.
----------------

$val variable is missing.

Even more strange: if I replace "my $val;" with "$val;", this does not happen at all:

----------------
CREATE OR REPLACE FUNCTION foo() RETURNS void
AS
$$
$val;

sub init
{
$val = @_[0];
elog(NOTICE, "1: @_[0]\n");
}

&init(12);
elog(NOTICE, "2: $val\n");
$$
LANGUAGE 'plperl';
----------------

Now I can call the function with

----------------
select * from foo();
----------------

it works as expected:

----------------
NOTICE: 1: 12

NOTICE: 2: 12

Total query runtime: 390 ms.
Data retrieval runtime: 797 ms.
1 rows retrieved.
----------------

Am I missing something maybe? It sounds like a bug with lexical variables to me...

Cheers,

----------------------------------
Philippe Lang, Ing. Dipl. EPFL
Attik System
rte de la Fonderie 2
1700 Fribourg
Switzerland
http://www.attiksystem.ch

Tel: +41 (26) 422 13 75
Fax: +41 (26) 422 13 76

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kenneth Downs 2006-06-23 11:30:22 Re: minimizing downtime when upgrading
Previous Message Marco Bizzarri 2006-06-23 07:10:28 Documentation of the Front End/Back End Protocol for Large Objects