Sophie

Sophie

distrib > Mageia > 7 > i586 > by-pkgid > 9b6cc37ce608401d44f6535a0c7cb777 > files > 274

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>40.1. Overview of Event Trigger Behavior</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="event-triggers.html" title="Chapter 40. Event Triggers" /><link rel="next" href="event-trigger-matrix.html" title="40.2. Event Trigger Firing Matrix" /></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">40.1. Overview of Event Trigger Behavior</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="event-triggers.html" title="Chapter 40. Event Triggers">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="event-triggers.html" title="Chapter 40. Event Triggers">Up</a></td><th width="60%" align="center">Chapter 40. Event Triggers</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="event-trigger-matrix.html" title="40.2. Event Trigger Firing Matrix">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="EVENT-TRIGGER-DEFINITION"><div class="titlepage"><div><div><h2 class="title" style="clear: both">40.1. Overview of Event Trigger Behavior</h2></div></div></div><p>
     An event trigger fires whenever the event with which it is associated
     occurs in the database in which it is defined. Currently, the only
     supported events are
     <code class="literal">ddl_command_start</code>,
     <code class="literal">ddl_command_end</code>,
     <code class="literal">table_rewrite</code>
     and <code class="literal">sql_drop</code>.
     Support for additional events may be added in future releases.
   </p><p>
     The <code class="literal">ddl_command_start</code> event occurs just before the
     execution of a <code class="literal">CREATE</code>, <code class="literal">ALTER</code>, <code class="literal">DROP</code>,
     <code class="literal">SECURITY LABEL</code>,
     <code class="literal">COMMENT</code>, <code class="literal">GRANT</code> or <code class="literal">REVOKE</code>
     command.  No check whether the affected object exists or doesn't exist is
     performed before the event trigger fires.
     As an exception, however, this event does not occur for
     DDL commands targeting shared objects — databases, roles, and tablespaces
     — or for commands targeting event triggers themselves.  The event trigger
     mechanism does not support these object types.
     <code class="literal">ddl_command_start</code> also occurs just before the execution of a
     <code class="literal">SELECT INTO</code> command, since this is equivalent to
     <code class="literal">CREATE TABLE AS</code>.
   </p><p>
    The <code class="literal">ddl_command_end</code> event occurs just after the execution of
    this same set of commands.  To obtain more details on the <acronym class="acronym">DDL</acronym>
    operations that took place, use the set-returning function
    <code class="literal">pg_event_trigger_ddl_commands()</code> from the
    <code class="literal">ddl_command_end</code> event trigger code (see
    <a class="xref" href="functions-event-triggers.html" title="9.28. Event Trigger Functions">Section 9.28</a>).  Note that the trigger fires
    after the actions have taken place (but before the transaction commits),
    and thus the system catalogs can be read as already changed.
   </p><p>
    The <code class="literal">sql_drop</code> event occurs just before the
    <code class="literal">ddl_command_end</code> event trigger for any operation that drops
    database objects.  To list the objects that have been dropped, use the
    set-returning function <code class="literal">pg_event_trigger_dropped_objects()</code> from the
    <code class="literal">sql_drop</code> event trigger code (see
    <a class="xref" href="functions-event-triggers.html" title="9.28. Event Trigger Functions">Section 9.28</a>). Note that
    the trigger is executed after the objects have been deleted from the
    system catalogs, so it's not possible to look them up anymore.
   </p><p>
    The <code class="literal">table_rewrite</code> event occurs just before a table is
    rewritten by some actions of the commands <code class="literal">ALTER TABLE</code> and
    <code class="literal">ALTER TYPE</code>.  While other
    control statements are available to rewrite a table,
    like <code class="literal">CLUSTER</code> and <code class="literal">VACUUM</code>,
    the <code class="literal">table_rewrite</code> event is not triggered by them.
   </p><p>
     Event triggers (like other functions) cannot be executed in an aborted
     transaction.  Thus, if a DDL command fails with an error, any associated
     <code class="literal">ddl_command_end</code> triggers will not be executed.  Conversely,
     if a <code class="literal">ddl_command_start</code> trigger fails with an error, no
     further event triggers will fire, and no attempt will be made to execute
     the command itself.  Similarly, if a <code class="literal">ddl_command_end</code> trigger
     fails with an error, the effects of the DDL statement will be rolled
     back, just as they would be in any other case where the containing
     transaction aborts.
   </p><p>
     For a complete list of commands supported by the event trigger mechanism,
     see <a class="xref" href="event-trigger-matrix.html" title="40.2. Event Trigger Firing Matrix">Section 40.2</a>.
   </p><p>
     Event triggers are created using the command <a class="xref" href="sql-createeventtrigger.html" title="CREATE EVENT TRIGGER"><span class="refentrytitle">CREATE EVENT TRIGGER</span></a>.
     In order to create an event trigger, you must first create a function with
     the special return type <code class="literal">event_trigger</code>.  This function
     need not (and may not) return a value; the return type serves merely as
     a signal that the function is to be invoked as an event trigger.
   </p><p>
     If more than one event trigger is defined for a particular event, they will
     fire in alphabetical order by trigger name.
   </p><p>
     A trigger definition can also specify a <code class="literal">WHEN</code>
     condition so that, for example, a <code class="literal">ddl_command_start</code>
     trigger can be fired only for particular commands which the user wishes
     to intercept. A common use of such triggers is to restrict the range of
     DDL operations which users may perform.
   </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="event-triggers.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="event-triggers.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="event-trigger-matrix.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 40. Event Triggers </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 40.2. Event Trigger Firing Matrix</td></tr></table></div></body></html>