Skip site navigation (1) Skip section navigation (2)

Re: arrays as pl/perl input arguments [PATCH]

From: Alex Hunsaker <badalex(at)gmail(dot)com>
To: Alexey Klyukin <alexk(at)commandprompt(dot)com>
Cc: "David E(dot) Wheeler" <david(at)kineticode(dot)com>, pgsql-hackers(at)postgresql(dot)org, Andrew Dunstan <andrew(at)dunslane(dot)net>
Subject: Re: arrays as pl/perl input arguments [PATCH]
Date: 2011-01-15 22:48:28
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers
On Wed, Jan 12, 2011 at 13:04, Alexey Klyukin <alexk(at)commandprompt(dot)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"
CONTEXT:  PL/Perl function "takes_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: pg_to_perl_arrays_kind_of.patch.gz
Description: application/x-gzip (4.9 KB)

In response to


pgsql-hackers by date

Next:From: Greg SmithDate: 2011-01-15 22:57:02
Subject: Re: Spread checkpoint sync
Previous:From: Josh BerkusDate: 2011-01-15 22:34:11
Subject: Re: auto-sizing wal_buffers

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group