Home Explore Blog CI



postgresql

5th chunk of `doc/src/sgml/ref/create_trigger.sgml`
dbc80da1db7060ea2642d1c5c1fd3dc87181236544043c730000000100000fa2
 (optionally schema-qualified) of the table, view, or foreign
      table the trigger is for.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">referenced_table_name</replaceable></term>
    <listitem>
     <para>
      The (possibly schema-qualified) name of another table referenced by the
      constraint.  This option is used for foreign-key constraints and is not
      recommended for general use.  This can only be specified for
      constraint triggers.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>DEFERRABLE</literal></term>
    <term><literal>NOT DEFERRABLE</literal></term>
    <term><literal>INITIALLY IMMEDIATE</literal></term>
    <term><literal>INITIALLY DEFERRED</literal></term>
    <listitem>
     <para>
      The default timing of the trigger.
      See the <xref linkend="sql-createtable"/> documentation for details of
      these constraint options.  This can only be specified for constraint
      triggers.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>REFERENCING</literal></term>
    <listitem>
     <para>
      This keyword immediately precedes the declaration of one or two
      relation names that provide access to the transition relations of the
      triggering statement.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>OLD TABLE</literal></term>
    <term><literal>NEW TABLE</literal></term>
    <listitem>
     <para>
      This clause indicates whether the following relation name is for the
      before-image transition relation or the after-image transition
      relation.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">transition_relation_name</replaceable></term>
    <listitem>
     <para>
      The (unqualified) name to be used within the trigger for this
      transition relation.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><literal>FOR EACH ROW</literal></term>
    <term><literal>FOR EACH STATEMENT</literal></term>

    <listitem>
     <para>
      This specifies whether the trigger function should be fired
      once for every row affected by the trigger event, or just once
      per SQL statement. If neither is specified, <literal>FOR EACH
      STATEMENT</literal> is the default.  Constraint triggers can only
      be specified <literal>FOR EACH ROW</literal>.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">condition</replaceable></term>
    <listitem>
     <para>
      A Boolean expression that determines whether the trigger function
      will actually be executed.  If <literal>WHEN</literal> is specified, the
      function will only be called if the <replaceable
      class="parameter">condition</replaceable> returns <literal>true</literal>.
      In <literal>FOR EACH ROW</literal> triggers, the <literal>WHEN</literal>
      condition can refer to columns of the old and/or new row values
      by writing <literal>OLD.<replaceable
      class="parameter">column_name</replaceable></literal> or
      <literal>NEW.<replaceable
      class="parameter">column_name</replaceable></literal> respectively.
      Of course, <literal>INSERT</literal> triggers cannot refer to <literal>OLD</literal>
      and <literal>DELETE</literal> triggers cannot refer to <literal>NEW</literal>.
     </para>

     <para><literal>INSTEAD OF</literal> triggers do not support <literal>WHEN</literal>
      conditions.
     </para>

     <para>
      Currently, <literal>WHEN</literal> expressions cannot contain
      subqueries.
     </para>

     <para>
      Note that for constraint triggers, evaluation of the <literal>WHEN</literal>
      condition is not deferred, but occurs immediately after the row update
      operation is performed. If the condition does not evaluate to true then
      the trigger

Title: CREATE TRIGGER Parameters (Continued)
Summary
This section continues the description of CREATE TRIGGER parameters, including REFERENCING, OLD TABLE, NEW TABLE, transition_relation_name, FOR EACH ROW/STATEMENT, and WHEN condition. It explains how to access transition relations and how the trigger function is executed based on the triggering event (per row or per statement). The WHEN condition specifies a boolean expression to determine if the trigger function is executed, with access to OLD and NEW row values in FOR EACH ROW triggers. INSTEAD OF triggers do not support WHEN conditions.