Home Explore Blog CI



postgresql

2nd chunk of `doc/src/sgml/ref/create_event_trigger.sgml`
90a0ad892f6321dc5c718dccf1386644f8c6d37c9c242b530000000100000e38
 name must be unique within
      the database.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">event</replaceable></term>
    <listitem>
     <para>
      The name of the event that triggers a call to the given function.
      See <xref linkend="event-trigger-definition"/> for more information
      on event names.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">filter_variable</replaceable></term>
    <listitem>
     <para>
      The name of a variable used to filter events.  This makes it possible
      to restrict the firing of the trigger to a subset of the cases in which
      it is supported.  Currently the only supported
      <replaceable class="parameter">filter_variable</replaceable>
      is <literal>TAG</literal>.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">filter_value</replaceable></term>
    <listitem>
     <para>
      A list of values for the
      associated <replaceable class="parameter">filter_variable</replaceable>
      for which the trigger should fire.  For <literal>TAG</literal>, this means a
      list of command tags (e.g., <literal>'DROP FUNCTION'</literal>).
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term><replaceable class="parameter">function_name</replaceable></term>
    <listitem>
     <para>
      A user-supplied function that is declared as taking no argument and
      returning type <literal>event_trigger</literal>.
     </para>

     <para>
      In the syntax of <literal>CREATE EVENT TRIGGER</literal>, the keywords
      <literal>FUNCTION</literal> and <literal>PROCEDURE</literal> are
      equivalent, but the referenced function must in any case be a function,
      not a procedure.  The use of the keyword <literal>PROCEDURE</literal>
      here is historical and deprecated.
     </para>
    </listitem>
   </varlistentry>

  </variablelist>
 </refsect1>

 <refsect1 id="sql-createeventtrigger-notes">
  <title>Notes</title>

  <para>
   Only superusers can create event triggers.
  </para>

  <para>
   Event triggers are disabled in single-user mode (see <xref
   linkend="app-postgres"/>) as well as when
   <xref linkend="guc-event-triggers"/> is set to <literal>false</literal>.
   If an erroneous event trigger disables the database so much that you can't
   even drop the trigger, restart with <xref linkend="guc-event-triggers"/>
   set to <literal>false</literal> to temporarily disable event triggers, or
   in single-user mode, and you'll be able to do that.
  </para>
 </refsect1>

 <refsect1 id="sql-createeventtrigger-examples">
  <title>Examples</title>

  <para>
   Forbid the execution of any <link linkend="ddl">DDL</link> command:

<programlisting>
CREATE OR REPLACE FUNCTION abort_any_command()
  RETURNS event_trigger
 LANGUAGE plpgsql
  AS $$
BEGIN
  RAISE EXCEPTION 'command % is disabled', tg_tag;
END;
$$;

CREATE EVENT TRIGGER abort_ddl ON ddl_command_start
   EXECUTE FUNCTION abort_any_command();
</programlisting></para>
 </refsect1>

 <refsect1 id="sql-createeventtrigger-compatibility">
  <title>Compatibility</title>

  <para>
   There is no <command>CREATE EVENT TRIGGER</command> statement in the
   SQL standard.
  </para>

 </refsect1>

 <refsect1>
  <title>See Also</title>

  <simplelist type="inline">
   <member><xref linkend="sql-altereventtrigger"/></member>
   <member><xref linkend="sql-dropeventtrigger"/></member>
   <member><xref linkend="sql-createfunction"/></member>
  </simplelist>
 </refsect1>
</refentry>

Title: CREATE EVENT TRIGGER: Parameters, Notes, Examples, and Compatibility
Summary
This section details the parameters for the CREATE EVENT TRIGGER command, including the trigger name, event, filter variable (TAG), filter values, and the function to execute. It notes that only superusers can create event triggers and that they are disabled in single-user mode or when event_triggers is set to false. An example demonstrates how to forbid the execution of any DDL command. The command is not part of the SQL standard. Related commands are ALTER EVENT TRIGGER, DROP EVENT TRIGGER, and CREATE FUNCTION.