diff options
Diffstat (limited to 'doc/src')
-rw-r--r-- | doc/src/sgml/plperl.sgml | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/doc/src/sgml/plperl.sgml b/doc/src/sgml/plperl.sgml index 4150998808c..a481accd868 100644 --- a/doc/src/sgml/plperl.sgml +++ b/doc/src/sgml/plperl.sgml @@ -199,6 +199,42 @@ select returns_array(); </para> <para> + Perl passes <productname>PostgreSQL</productname> arrays as a blessed + PostgreSQL::InServer::ARRAY object. This object may be treated as an array + reference or a string, allowing for backwards compatibility with Perl + code written for <productname>PostgreSQL</productname> versions below 9.1 to + run. For example: + +<programlisting> +CREATE OR REPLACE FUNCTION concat_array_elements(text[]) RETURNS TEXT AS $$ + my $arg = shift; + my $result = ""; + return undef if (!defined $arg); + + # as an array reference + for (@$arg) { + $result .= $_; + } + + # also works as a string + $result .= $arg; + + return $result; +$$ LANGUAGE plperl; + +SELECT concat_array_elements(ARRAY['PL','/','Perl']); +</programlisting> + + <note> + <para> + Multi-dimensional arrays are represented as references to + lower-dimensional arrays of references in a way common to every Perl + programmer. + </para> + </note> + </para> + + <para> Composite-type arguments are passed to the function as references to hashes. The keys of the hash are the attribute names of the composite type. Here is an example: @@ -742,6 +778,22 @@ SELECT release_hosts_query(); <varlistentry> <indexterm> + <primary>encode_typed_literal</primary> + <secondary>in PL/Perl</secondary> + </indexterm> + + <term><literal><function>encode_typed_literal(<replaceable>value</replaceable>, <replaceable>typename</replaceable>)</function></literal></term> + <listitem> + <para> + Converts a Perl variable to the value of the datatype passed as a + second argument and returns a string representation of this value. + Correctly handles nested arrays and values of composite types. + </para> + </listitem> + </varlistentry> + + <varlistentry> + <indexterm> <primary>encode_array_constructor</primary> <secondary>in PL/Perl</secondary> </indexterm> @@ -775,8 +827,24 @@ SELECT release_hosts_query(); </listitem> </varlistentry> + <varlistentry> + <indexterm> + <primary>is_array_ref</primary> + <secondary>in PL/Perl</secondary> + </indexterm> + + <term><literal><function>is_array_ref(<replaceable>argument</replaceable>)</function></literal></term> + <listitem> + <para> + Returns a true value if the given argument may be treated as an + array reference, that is, if ref of the argument is <literal>ARRAY</> or + <literal>PostgreSQL::InServer::ARRAY</>. Returns false otherwise. + </para> + </listitem> + </varlistentry> + </variablelist> - </sect2> + </sect2> </sect1> <sect1 id="plperl-global"> |