Re: another plperl bug

Поиск
Список
Период
Сортировка
От Richard Poole
Тема Re: another plperl bug
Дата
Msg-id 20041123190019.GA22311@guests.deus.net
обсуждение исходный текст
Ответ на Re: another plperl bug  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: another plperl bug  (Andrew Dunstan <andrew@dunslane.net>)
Список pgsql-hackers
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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Stefan Kaltenbrunner
Дата:
Сообщение: Re: OpenBSD/Sparc status
Следующее
От: Tom Lane
Дата:
Сообщение: Re: another plperl bug