diff options
author | Andrew Dunstan | 2007-05-04 14:55:32 +0000 |
---|---|---|
committer | Andrew Dunstan | 2007-05-04 14:55:32 +0000 |
commit | 9c3f35e1cec3f77d3e6a73553312e967bae3566c (patch) | |
tree | 68a43354e4235ec630ebd2bd036f8ae026ce4e2e | |
parent | 48f15c1e72ed39a7d03db005c0d9ec51ea79ccf6 (diff) |
Make clearer how arguments and return values in pl/perl are escaped. This is to clarify the situation that Theo Schlossnagle recently reported on -bugs.
-rw-r--r-- | doc/src/sgml/plperl.sgml | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/doc/src/sgml/plperl.sgml b/doc/src/sgml/plperl.sgml index b1f8030c33..6c1092350e 100644 --- a/doc/src/sgml/plperl.sgml +++ b/doc/src/sgml/plperl.sgml @@ -138,13 +138,43 @@ $$ LANGUAGE plperl; </para> <para> + Anything in a function argument that is not a reference is + a string, which is in the standard <productname>PostgreSQL</productname> + 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 <type>bytea</> into unescaped binary + data: + +<programlisting> + my $arg = shift; + $arg =~ s!\\(\d{3})!chr(oct($1))!ge; +</programlisting> + + </para> + + <para> + Similarly, values passed back to <productname>PostgreSQL</productname> + must be in the external text representation format. For example, here + is how to escape binary data for a return value of type <type>bytea</>: + +<programlisting> + $retval =~ s!([^ -~])!sprintf("\\%03o",ord($1))!ge; + return $retval; +</programlisting> + + </para> + + <para> Perl can return <productname>PostgreSQL</productname> arrays as references to Perl arrays. Here is an example: <programlisting> 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(); |