trigger which fired.
</para>
</listitem>
</varlistentry>
<varlistentry id="plpgsql-dml-trigger-tg-when">
<term><varname>TG_WHEN</varname> <type>text</type></term>
<listitem>
<para>
<literal>BEFORE</literal>, <literal>AFTER</literal>, or
<literal>INSTEAD OF</literal>, depending on the trigger's definition.
</para>
</listitem>
</varlistentry>
<varlistentry id="plpgsql-dml-trigger-tg-level">
<term><varname>TG_LEVEL</varname> <type>text</type></term>
<listitem>
<para>
<literal>ROW</literal> or <literal>STATEMENT</literal>,
depending on the trigger's definition.
</para>
</listitem>
</varlistentry>
<varlistentry id="plpgsql-dml-trigger-tg-op">
<term><varname>TG_OP</varname> <type>text</type></term>
<listitem>
<para>
operation for which the trigger was fired:
<literal>INSERT</literal>, <literal>UPDATE</literal>,
<literal>DELETE</literal>, or <literal>TRUNCATE</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry id="plpgsql-dml-trigger-tg-relid">
<term><varname>TG_RELID</varname> <type>oid</type> (references <link linkend="catalog-pg-class"><structname>pg_class</structname></link>.<structfield>oid</structfield>)</term>
<listitem>
<para>
object ID of the table that caused the trigger invocation.
</para>
</listitem>
</varlistentry>
<varlistentry id="plpgsql-dml-trigger-tg-relname">
<term><varname>TG_RELNAME</varname> <type>name</type></term>
<listitem>
<para>
table that caused the trigger
invocation. This is now deprecated, and could disappear in a future
release. Use <literal>TG_TABLE_NAME</literal> instead.
</para>
</listitem>
</varlistentry>
<varlistentry id="plpgsql-dml-trigger-tg-table-name">
<term><varname>TG_TABLE_NAME</varname> <type>name</type></term>
<listitem>
<para>
table that caused the trigger invocation.
</para>
</listitem>
</varlistentry>
<varlistentry id="plpgsql-dml-trigger-tg-table-schema">
<term><varname>TG_TABLE_SCHEMA</varname> <type>name</type></term>
<listitem>
<para>
schema of the table that caused the trigger invocation.
</para>
</listitem>
</varlistentry>
<varlistentry id="plpgsql-dml-trigger-tg-nargs">
<term><varname>TG_NARGS</varname> <type>integer</type></term>
<listitem>
<para>
number of arguments given to the trigger
function in the <command>CREATE TRIGGER</command> statement.
</para>
</listitem>
</varlistentry>
<varlistentry id="plpgsql-dml-trigger-tg-argv">
<term><varname>TG_ARGV</varname> <type>text[]</type></term>
<listitem>
<para>
arguments from
the <command>CREATE TRIGGER</command> statement.
The index counts from 0. Invalid
indexes (less than 0 or greater than or equal to <varname>tg_nargs</varname>)
result in a null value.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<para>
A trigger function must return either <symbol>NULL</symbol> or a
record/row value having exactly the structure of the table the
trigger was fired for.
</para>
<para>
Row-level triggers fired <literal>BEFORE</literal> can return null to signal the
trigger manager to skip the rest of the operation for this row
(i.e., subsequent triggers are not fired, and the
<command>INSERT</command>/<command>UPDATE</command>/<command>DELETE</command> does not occur
for this row). If a nonnull
value is returned then the operation proceeds with that row value.
Returning a row value different from the original value
of <varname>NEW</varname> alters the row that will be inserted or
updated. Thus, if the trigger function wants the triggering
action to succeed normally without altering the