<term><literal>$_TD->{table_schema}</literal></term>
<listitem>
<para>
Name of the schema in which the table on which the trigger fired, is
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>$_TD->{argc}</literal></term>
<listitem>
<para>
Number of arguments of the trigger function
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>@{$_TD->{args}}</literal></term>
<listitem>
<para>
Arguments of the trigger function. Does not exist if <literal>$_TD->{argc}</literal> is 0.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
Row-level triggers can return one of the following:
<variablelist>
<varlistentry>
<term><literal>return;</literal></term>
<listitem>
<para>
Execute the operation
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>"SKIP"</literal></term>
<listitem>
<para>
Don't execute the operation
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>"MODIFY"</literal></term>
<listitem>
<para>
Indicates that the <literal>NEW</literal> row was modified by
the trigger function
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
Here is an example of a trigger function, illustrating some of the
above:
<programlisting>
CREATE TABLE test (
i int,
v varchar
);
CREATE OR REPLACE FUNCTION valid_id() RETURNS trigger AS $$
if (($_TD->{new}{i} >= 100) || ($_TD->{new}{i} <= 0)) {
return "SKIP"; # skip INSERT/UPDATE command
} elsif ($_TD->{new}{v} ne "immortal") {
$_TD->{new}{v} .= "(modified by trigger)";
return "MODIFY"; # modify row and execute INSERT/UPDATE command
} else {
return; # execute INSERT/UPDATE command
}
$$ LANGUAGE plperl;
CREATE TRIGGER test_valid_id_trig
BEFORE INSERT OR UPDATE ON test
FOR EACH ROW EXECUTE FUNCTION valid_id();
</programlisting>
</para>
</sect1>
<sect1 id="plperl-event-triggers">
<title>PL/Perl Event Triggers</title>
<para>
PL/Perl can be used to write event trigger functions. In an event trigger
function, the hash reference <varname>$_TD</varname> contains information
about the current trigger event. <varname>$_TD</varname> is a global variable,
which gets a separate local value for each invocation of the trigger. The
fields of the <varname>$_TD</varname> hash reference are:
<variablelist>
<varlistentry>
<term><literal>$_TD->{event}</literal></term>
<listitem>
<para>
The name of the event the trigger is fired for.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><literal>$_TD->{tag}</literal></term>
<listitem>
<para>
The command tag for which the trigger is fired.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
The return value of the trigger function is ignored.
</para>
<para>
Here is an example of an event trigger function, illustrating some of the
above:
<programlisting>
CREATE OR REPLACE FUNCTION perlsnitch() RETURNS event_trigger AS $$
elog(NOTICE, "perlsnitch: " . $_TD->{event} . " " . $_TD->{tag} . " ");
$$ LANGUAGE plperl;
CREATE EVENT TRIGGER perl_a_snitch
ON ddl_command_start
EXECUTE FUNCTION perlsnitch();
</programlisting>
</para>
</sect1>
<sect1 id="plperl-under-the-hood">
<title>PL/Perl Under the Hood</title>
<sect2 id="plperl-config">
<title>Configuration</title>
<para>
This section lists configuration parameters that affect <application>PL/Perl</application>.
</para>
<variablelist>
<varlistentry id="guc-plperl-on-init" xreflabel="plperl.on_init">
<term>
<varname>plperl.on_init</varname> (<type>string</type>)