Re: another plperl bug

From: Richard Poole <rp(at)guests(dot)deus(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: another plperl bug
Date: 2004-11-23 19:00:19
Message-ID: 20041123190019.GA22311@guests.deus.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

On Tue, Nov 23, 2004 at 11:37:22AM -0500, Tom Lane wrote:
>
> > CREATE FUNCTION test1() RETURNS TEXT AS $$
> > return ["test"];
> > $$ LANGUAGE plperl;
>
> > SELECT test1();
> > test1
> > ------------------
> > ARRAY(0x8427a58)
> > (1 row)
>
> This is exactly what Perl will do if you try to coerce an array to a
> scalar:
>
> $ perl -e 'print ["test 1"], "\n"'
> ARRAY(0xa03ec28)
> $

To go a stage further, there's no array-to-scalar coercion happening
there; the [] syntax gives you a reference to an anonymous array, and
a reference to an array is a scalar, even when evaluated in list
context, as Tom's example is. If you wanted to return a list from
a sub in perl you'd just go return("test 1", "test 2").

> so I don't think a Perl programmer would find it surprising; if anything
> he'd probably complain if we *didn't* do that.

Indeed. It would be Perlish to have some magic so that when you called
one PL/Perl function from another you could return an array ref from
the inner one and have it Do What You Mean in the outer one, too.

Richard

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2004-11-23 19:12:46 Re: another plperl bug
Previous Message Stefan Kaltenbrunner 2004-11-23 18:53:54 Re: OpenBSD/Sparc status

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2004-11-23 19:12:46 Re: another plperl bug
Previous Message Michael Fuhr 2004-11-23 18:15:12 Re: another plperl bug