Re: arrays as pl/perl input arguments [PATCH] - Mailing list pgsql-hackers

From Alex Hunsaker
Subject Re: arrays as pl/perl input arguments [PATCH]
Date
Msg-id AANLkTikwGVEEPFVm7P9vyWXYVHjdzo_V+mJa_GHK-3JN@mail.gmail.com
Whole thread Raw
In response to Re: arrays as pl/perl input arguments [PATCH]  (Alexey Klyukin <alexk@commandprompt.com>)
Responses Re: arrays as pl/perl input arguments [PATCH]  (Alex Hunsaker <badalex@gmail.com>)
List pgsql-hackers
On Wed, Jan 12, 2011 at 13:04, Alexey Klyukin <alexk@commandprompt.com> wrote:
>
> On Jan 12, 2011, at 8:52 PM, David E. Wheeler wrote:
>
>> On Jan 12, 2011, at 5:14 AM, Alexey Klyukin wrote:
>>
>>> You mean packing both a string representation and a reference to a single SV * value?
>>
>> Dunno, I'm not a guts guy.
>
> Well, neither me (I haven't used much of the guts api there).

Find attached a proof of concept that modifies Alexey's patch to do
the above (using the overload example I and others posted).

Arrays have a reference of 'PostgreSQL::InServer::ARRAY'-- mainly to
be consistent with the other PL/Perl packages we have. It also lets
you match ref() =~ m/ARRAY$/ to make it a tad easier to figure out if
something is an array.

The other thing to note is I only applied this to the 'top' array.
That is when you have a multidimensional array, its children are
'real' arrays:

 create or replace function takes_array(text[]) returns void as $$
 my $array = shift;

 elog(NOTICE, ref $array);
 elog(NOTICE, ref $_) for (@$array);

$$ language plperl;

 select takes_array('{{1}, {2, 3}}'::text[]);
NOTICE:  PostgreSQL::InServer::ARRAY
CONTEXT:  PL/Perl function "takes_array"
NOTICE:  ARRAY
CONTEXT:  PL/Perl function "takes_array"
NOTICE:  ARRAY
CONTEXT:  PL/Perl function "takes_array"

We could change that so _all_ arrays have a ref of
PostgreSQL::InServer::ARRAY. However I thought it would be nice to
easily use built-ins, this way you can just 'cast' away just the top
level without having to recurse to children (my @arr = @$array).

This also will create a string representation if and when you try to
use it as a string.  It currently lacks row support in the stringify
case (and I left the regression test Alexey added for that failing) so
we would need to fix that up if we want to go down this road.

Thoughts?  Should I polish this a bit more?  Or do we like the GUC better?

Attachment

pgsql-hackers by date:

Previous
From: Josh Berkus
Date:
Subject: Re: auto-sizing wal_buffers
Next
From: Greg Smith
Date:
Subject: Re: Spread checkpoint sync