A tuple is passed as a reference to a hash. The keys are the names
A tuple is passed as a reference to a hash. The keys are the names
of the fields in the tuples. The hash values are values of the
of the fields in the tuples. The hash values are values of the
...
@@ -151,7 +155,7 @@ CREATE FUNCTION empcomp(employee) RETURNS integer AS '
...
@@ -151,7 +155,7 @@ CREATE FUNCTION empcomp(employee) RETURNS integer AS '
</tip>
</tip>
<para>
<para>
The new function <function>empcomp</function> can used like:
The new function <function>empcomp</function> can be used like:
<programlisting>
<programlisting>
SELECT name, empcomp(employee) FROM employee;
SELECT name, empcomp(employee) FROM employee;
</programlisting>
</programlisting>
...
@@ -165,18 +169,22 @@ CREATE FUNCTION badfunc() RETURNS integer AS '
...
@@ -165,18 +169,22 @@ CREATE FUNCTION badfunc() RETURNS integer AS '
open(TEMP, ">/tmp/badfile");
open(TEMP, ">/tmp/badfile");
print TEMP "Gotcha!\n";
print TEMP "Gotcha!\n";
return 1;
return 1;
' LANGUAGE 'plperl';
' LANGUAGE plperl;
</programlisting>
</programlisting>
The creation of the function will succeed, but executing it will not.
The creation of the function will succeed, but executing it will not.
</para>
<para>
Note that if same function was created by superuser using language
Note that if same function was created by superuser using language
<literal>plperlu</>, execution would succeed.
<literal>plperlu</>, execution would succeed.
</para>
</para>
<para>
<para>
Access to database itself from your Perl function can be done via
Access to database itself from your Perl function can be done via
an experimental module <ulink url="http://www.formenos.org/PgSPI/"><literal>DBD::PgSPI</literal></ulink>. This module makes available a <acronym>DBI</>-compliant
an experimental module <ulink
database-handle named <varname>$pg_dbh</varname>, and you can use that to make queries with