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

arrays as pl/perl input arguments [PATCH]

From: Alexey Klyukin <alexk(at)commandprompt(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>
Subject: arrays as pl/perl input arguments [PATCH]
Date: 2011-01-11 22:25:35
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-hackers

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;
	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}');
 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

Alexey Klyukin
The PostgreSQL Company - Command Prompt, Inc.

Attachment: pg_to_perl_arrays.diff
Description: application/octet-stream (21.2 KB)


pgsql-hackers by date

Next:From: Lukas EderDate: 2011-01-11 22:54:19
Subject: Re: Fwd: Weird issues when reading UDT from stored function
Previous:From: David FetterDate: 2011-01-11 22:11:32
Subject: Re: Allowing multiple concurrent base backups

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