Sophie

Sophie

distrib > Mageia > 7 > x86_64 > by-pkgid > 9b6cc37ce608401d44f6535a0c7cb777 > files > 837

postgresql11-docs-11.5-1.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>CREATE EVENT TRIGGER</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="sql-createdomain.html" title="CREATE DOMAIN" /><link rel="next" href="sql-createextension.html" title="CREATE EXTENSION" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">CREATE EVENT TRIGGER</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="sql-createdomain.html" title="CREATE DOMAIN">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="sql-commands.html" title="SQL Commands">Up</a></td><th width="60%" align="center">SQL Commands</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 11.5 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="sql-createextension.html" title="CREATE EXTENSION">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="SQL-CREATEEVENTTRIGGER"><div class="titlepage"></div><a id="id-1.9.3.63.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle">CREATE EVENT TRIGGER</span></h2><p>CREATE EVENT TRIGGER — define a new event trigger</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
CREATE EVENT TRIGGER <em class="replaceable"><code>name</code></em>
    ON <em class="replaceable"><code>event</code></em>
    [ WHEN <em class="replaceable"><code>filter_variable</code></em> IN (filter_value [, ... ]) [ AND ... ] ]
    EXECUTE { FUNCTION | PROCEDURE } <em class="replaceable"><code>function_name</code></em>()
</pre></div><div class="refsect1" id="id-1.9.3.63.5"><h2>Description</h2><p>
   <code class="command">CREATE EVENT TRIGGER</code> creates a new event trigger.
   Whenever the designated event occurs and the <code class="literal">WHEN</code> condition
   associated with the trigger, if any, is satisfied, the trigger function
   will be executed.  For a general introduction to event triggers, see
   <a class="xref" href="event-triggers.html" title="Chapter 40. Event Triggers">Chapter 40</a>.  The user who creates an event trigger
   becomes its owner.
  </p></div><div class="refsect1" id="id-1.9.3.63.6"><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt><dd><p>
      The name to give the new trigger.  This name must be unique within
      the database.
     </p></dd><dt><span class="term"><em class="replaceable"><code>event</code></em></span></dt><dd><p>
      The name of the event that triggers a call to the given function.
      See <a class="xref" href="event-trigger-definition.html" title="40.1. Overview of Event Trigger Behavior">Section 40.1</a> for more information
      on event names.
     </p></dd><dt><span class="term"><em class="replaceable"><code>filter_variable</code></em></span></dt><dd><p>
      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
      <em class="replaceable"><code>filter_variable</code></em>
      is <code class="literal">TAG</code>.
     </p></dd><dt><span class="term"><em class="replaceable"><code>filter_value</code></em></span></dt><dd><p>
      A list of values for the
      associated <em class="replaceable"><code>filter_variable</code></em>
      for which the trigger should fire.  For <code class="literal">TAG</code>, this means a
      list of command tags (e.g. <code class="literal">'DROP FUNCTION'</code>).
     </p></dd><dt><span class="term"><em class="replaceable"><code>function_name</code></em></span></dt><dd><p>
      A user-supplied function that is declared as taking no argument and
      returning type <code class="literal">event_trigger</code>.
     </p><p>
      In the syntax of <code class="literal">CREATE EVENT TRIGGER</code>, the keywords
      <code class="literal">FUNCTION</code> and <code class="literal">PROCEDURE</code> are
      equivalent, but the referenced function must in any case be a function,
      not a procedure.  The use of the keyword <code class="literal">PROCEDURE</code>
      here is historical and deprecated.
     </p></dd></dl></div></div><div class="refsect1" id="SQL-CREATEEVENTTRIGGER-NOTES"><h2>Notes</h2><p>
   Only superusers can create event triggers.
  </p><p>
   Event triggers are disabled in single-user mode (see <a class="xref" href="app-postgres.html" title="postgres"><span class="refentrytitle"><span class="application">postgres</span></span></a>).  If an erroneous event trigger disables the
   database so much that you can't even drop the trigger, restart in
   single-user mode and you'll be able to do that.
  </p></div><div class="refsect1" id="SQL-CREATEEVENTTRIGGER-EXAMPLES"><h2>Examples</h2><p>
   Forbid the execution of any <a class="link" href="ddl.html" title="Chapter 5. Data Definition">DDL</a> command:

</p><pre class="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();
</pre></div><div class="refsect1" id="SQL-CREATEEVENTTRIGGER-COMPATIBILITY"><h2>Compatibility</h2><p>
   There is no <code class="command">CREATE EVENT TRIGGER</code> statement in the
   SQL standard.
  </p></div><div class="refsect1" id="id-1.9.3.63.10"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-altereventtrigger.html" title="ALTER EVENT TRIGGER"><span class="refentrytitle">ALTER EVENT TRIGGER</span></a>, <a class="xref" href="sql-dropeventtrigger.html" title="DROP EVENT TRIGGER"><span class="refentrytitle">DROP EVENT TRIGGER</span></a>, <a class="xref" href="sql-createfunction.html" title="CREATE FUNCTION"><span class="refentrytitle">CREATE FUNCTION</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sql-createdomain.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="sql-commands.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sql-createextension.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">CREATE DOMAIN </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> CREATE EXTENSION</td></tr></table></div></body></html>