-
+
PL/Perl - Perl Procedural Language
function is strict or not.
+ Anything in a function argument that is not a reference is
+ a string, which is in the standard
PostgreSQL
+ external text representation for the relevant data type. In the case of
+ ordinary numeric or text types, Perl will just do the right thing and
+ the programmer will normally not have to worry about it. However, in
+ other cases the argument will need to be converted into a form that is
+ more usable in Perl. For example, here is how to convert an argument of
+ type bytea> into unescaped binary
+ data:
+
+ my $arg = shift;
+ $arg =~ s!\\(\d{3})!chr(oct($1))!ge;
+
+
+
+
+ Similarly, values passed back to
PostgreSQL
+ must be in the external text representation format. For example, here
+ is how to escape binary data for a return value of type bytea>:
+
+ $retval =~ s!([^ -~])!sprintf("\\%03o",ord($1))!ge;
+ return $retval;
+
+
+
+
Perl can return
PostgreSQL arrays as
references to Perl arrays. Here is an example:
CREATE OR REPLACE function returns_array()
RETURNS text[][] AS $$
- return [['a"b','c,d'],['e\\f','g']];
+ return [['a"b','c,d'],['e\\f','g']];
$$ LANGUAGE plperl;
select returns_array();