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

From Alexey Klyukin
Subject arrays as pl/perl input arguments [PATCH]
Date
Msg-id C0229C76-0CE8-4052-8A59-55FBC383210C@commandprompt.com
Whole thread Raw
Responses Re: arrays as pl/perl input arguments [PATCH]  ("David E. Wheeler" <david@kineticode.com>)
Re: arrays as pl/perl input arguments [PATCH]  (Tim Bunce <Tim.Bunce@pobox.com>)
List pgsql-hackers
Hello,

Here's the patch that improves handling of arrays as pl/perl function input
arguments, converting postgres arrays of arbitrary dimensions into perl array
references. It includes regression tests and a documentation changes, and it
builds and runs successfully on my mac os x and linux boxes. To maintain
compatibility with existing pl/perl code a new variable,
plperl.convert_array_arguments (better name?), is introduced. Its default
value is false, when set to true it triggers the new behavior, i.e.

SET plperl.convert_array_arguments = true;
CREATE OR REPLACE FUNCTION test_array(text[]) RETURNS TEXT AS $$
    my $arg = shift;
    if (ref $arg eq 'ARRAY') {
        return "array conversion is enabled";
    } else {
        return "array conversion is disabled";
    }
$$ LANGUAGE plperl;

test=# select test_array('{1,2,3}');
         test_array
-----------------------------
 array conversion is enabled
(1 row)

You can find other, less trivial examples, by examining plperl_array
regression test.

The implementation detects whether the input argument of a perl function is an
array, and calls plperl_ref_from_pg_array if it is. The latter obtains a flat
array of Datums from deconstruct_array and, using information about array
dimensions, recursively creates perl array references in split_array. To pass
array information between recursive calls a new 'plperl_array_info' struct was
added. Arrays as members of composite types are also handled in
plperl_hash_from_tuple.

/A
--
Alexey Klyukin
The PostgreSQL Company - Command Prompt, Inc.




Attachment

pgsql-hackers by date:

Previous
From: David Fetter
Date:
Subject: Re: Allowing multiple concurrent base backups
Next
From: Joel Jacobson
Date:
Subject: Re: pg_depend explained