arrays as input parameters in plperl

From: Alexey Klyukin <alexk(at)commandprompt(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: arrays as input parameters in plperl
Date: 2009-11-23 19:19:24
Message-ID: C523222B-9466-4E7D-8247-DDA3CC1BAA15@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I'd like to improve the way PL/Perl handles arrays as function input parameters. In PL/Perl arrays are passed as plain text strings, and getting a value of an array element requires additional perl code to parse that string. I'd like to make this easier by converting each postgresq array passed as an input parameter to the reference to the corresponding perl array. The patch in attachment illustrates this. it's limited to one-dimensional array output. The list of upcoming improvements is:

- convert n-dimensional array to the perl equivalent (a reference to a list of references)
- proper support for arrays of composite types
- compatibility with existing plperl functions by introducing a new custom variable, i.e. plperl.pass_array_refs that triggers the new behavior. I think it should be disabled by default.
- documentation and additional tests

The patch adds a new attribute to the plperl_proc_desc struct, that records whether Nth argument is an array. The function plperl_ref_from_pg_array does the actual job of converting array input parameter to the perl array reference. I considered writing a perl routine instead of a C function, although I though it would be less readable, more complex and slower due to double conversion of input. The disadvantage of a C function is a code duplication with array_out, on which my function is based, although it can be avoided by putting a relevant part of array_out into a separate function.

The patch is attached.

Anybody interested in this feature ? Ideas, improvements, suggestions ?

Regards,
--
Alexey Klyukin http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc

Attachment Content-Type Size
plperl_array.diff application/octet-stream 6.1 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2009-11-23 21:30:25 Re: named generic constraints [feature request]
Previous Message Pavel Stehule 2009-11-23 18:39:54 Re: named generic constraints [feature request]