gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
7.4KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!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>39.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 V1.79.1" /><link rel="prev" href="event-triggers.html" title="Chapter 39. Event Triggers" /><link rel="next" href="event-trigger-matrix.html" title="39.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">39.1. Overview of Event Trigger Behavior</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="event-triggers.html" title="Chapter 39. Event Triggers">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="event-triggers.html" title="Chapter 39. Event Triggers">Up</a></td><th width="60%" align="center">Chapter 39. Event Triggers</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="event-trigger-matrix.html" title="39.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">39.1. Overview of Event Trigger Behavior</h2></div></div></div><p>
  3. An event trigger fires whenever the event with which it is associated
  4. occurs in the database in which it is defined. Currently, the only
  5. supported events are
  6. <code class="literal">ddl_command_start</code>,
  7. <code class="literal">ddl_command_end</code>,
  8. <code class="literal">table_rewrite</code>
  9. and <code class="literal">sql_drop</code>.
  10. Support for additional events may be added in future releases.
  11. </p><p>
  12. The <code class="literal">ddl_command_start</code> event occurs just before the
  13. execution of a <code class="literal">CREATE</code>, <code class="literal">ALTER</code>, <code class="literal">DROP</code>,
  14. <code class="literal">SECURITY LABEL</code>,
  15. <code class="literal">COMMENT</code>, <code class="literal">GRANT</code> or <code class="literal">REVOKE</code>
  16. command. No check whether the affected object exists or doesn't exist is
  17. performed before the event trigger fires.
  18. As an exception, however, this event does not occur for
  19. DDL commands targeting shared objects — databases, roles, and tablespaces
  20. — or for commands targeting event triggers themselves. The event trigger
  21. mechanism does not support these object types.
  22. <code class="literal">ddl_command_start</code> also occurs just before the execution of a
  23. <code class="literal">SELECT INTO</code> command, since this is equivalent to
  24. <code class="literal">CREATE TABLE AS</code>.
  25. </p><p>
  26. The <code class="literal">ddl_command_end</code> event occurs just after the execution of
  27. this same set of commands. To obtain more details on the <acronym class="acronym">DDL</acronym>
  28. operations that took place, use the set-returning function
  29. <code class="literal">pg_event_trigger_ddl_commands()</code> from the
  30. <code class="literal">ddl_command_end</code> event trigger code (see
  31. <a class="xref" href="functions-event-triggers.html" title="9.28. Event Trigger Functions">Section 9.28</a>). Note that the trigger fires
  32. after the actions have taken place (but before the transaction commits),
  33. and thus the system catalogs can be read as already changed.
  34. </p><p>
  35. The <code class="literal">sql_drop</code> event occurs just before the
  36. <code class="literal">ddl_command_end</code> event trigger for any operation that drops
  37. database objects. To list the objects that have been dropped, use the
  38. set-returning function <code class="literal">pg_event_trigger_dropped_objects()</code> from the
  39. <code class="literal">sql_drop</code> event trigger code (see
  40. <a class="xref" href="functions-event-triggers.html" title="9.28. Event Trigger Functions">Section 9.28</a>). Note that
  41. the trigger is executed after the objects have been deleted from the
  42. system catalogs, so it's not possible to look them up anymore.
  43. </p><p>
  44. The <code class="literal">table_rewrite</code> event occurs just before a table is
  45. rewritten by some actions of the commands <code class="literal">ALTER TABLE</code> and
  46. <code class="literal">ALTER TYPE</code>. While other
  47. control statements are available to rewrite a table,
  48. like <code class="literal">CLUSTER</code> and <code class="literal">VACUUM</code>,
  49. the <code class="literal">table_rewrite</code> event is not triggered by them.
  50. </p><p>
  51. Event triggers (like other functions) cannot be executed in an aborted
  52. transaction. Thus, if a DDL command fails with an error, any associated
  53. <code class="literal">ddl_command_end</code> triggers will not be executed. Conversely,
  54. if a <code class="literal">ddl_command_start</code> trigger fails with an error, no
  55. further event triggers will fire, and no attempt will be made to execute
  56. the command itself. Similarly, if a <code class="literal">ddl_command_end</code> trigger
  57. fails with an error, the effects of the DDL statement will be rolled
  58. back, just as they would be in any other case where the containing
  59. transaction aborts.
  60. </p><p>
  61. For a complete list of commands supported by the event trigger mechanism,
  62. see <a class="xref" href="event-trigger-matrix.html" title="39.2. Event Trigger Firing Matrix">Section 39.2</a>.
  63. </p><p>
  64. 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>.
  65. In order to create an event trigger, you must first create a function with
  66. the special return type <code class="literal">event_trigger</code>. This function
  67. need not (and may not) return a value; the return type serves merely as
  68. a signal that the function is to be invoked as an event trigger.
  69. </p><p>
  70. If more than one event trigger is defined for a particular event, they will
  71. fire in alphabetical order by trigger name.
  72. </p><p>
  73. A trigger definition can also specify a <code class="literal">WHEN</code>
  74. condition so that, for example, a <code class="literal">ddl_command_start</code>
  75. trigger can be fired only for particular commands which the user wishes
  76. to intercept. A common use of such triggers is to restrict the range of
  77. DDL operations which users may perform.
  78. </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 39. Event Triggers </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 39.2. Event Trigger Firing Matrix</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1