gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

65 行
6.9KB

  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>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 V1.79.1" /><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 12.4 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">
  3. CREATE EVENT TRIGGER <em class="replaceable"><code>name</code></em>
  4. ON <em class="replaceable"><code>event</code></em>
  5. [ WHEN <em class="replaceable"><code>filter_variable</code></em> IN (filter_value [, ... ]) [ AND ... ] ]
  6. EXECUTE { FUNCTION | PROCEDURE } <em class="replaceable"><code>function_name</code></em>()
  7. </pre></div><div class="refsect1" id="id-1.9.3.63.5"><h2>Description</h2><p>
  8. <code class="command">CREATE EVENT TRIGGER</code> creates a new event trigger.
  9. Whenever the designated event occurs and the <code class="literal">WHEN</code> condition
  10. associated with the trigger, if any, is satisfied, the trigger function
  11. will be executed. For a general introduction to event triggers, see
  12. <a class="xref" href="event-triggers.html" title="Chapter 39. Event Triggers">Chapter 39</a>. The user who creates an event trigger
  13. becomes its owner.
  14. </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>
  15. The name to give the new trigger. This name must be unique within
  16. the database.
  17. </p></dd><dt><span class="term"><em class="replaceable"><code>event</code></em></span></dt><dd><p>
  18. The name of the event that triggers a call to the given function.
  19. See <a class="xref" href="event-trigger-definition.html" title="39.1. Overview of Event Trigger Behavior">Section 39.1</a> for more information
  20. on event names.
  21. </p></dd><dt><span class="term"><em class="replaceable"><code>filter_variable</code></em></span></dt><dd><p>
  22. The name of a variable used to filter events. This makes it possible
  23. to restrict the firing of the trigger to a subset of the cases in which
  24. it is supported. Currently the only supported
  25. <em class="replaceable"><code>filter_variable</code></em>
  26. is <code class="literal">TAG</code>.
  27. </p></dd><dt><span class="term"><em class="replaceable"><code>filter_value</code></em></span></dt><dd><p>
  28. A list of values for the
  29. associated <em class="replaceable"><code>filter_variable</code></em>
  30. for which the trigger should fire. For <code class="literal">TAG</code>, this means a
  31. list of command tags (e.g. <code class="literal">'DROP FUNCTION'</code>).
  32. </p></dd><dt><span class="term"><em class="replaceable"><code>function_name</code></em></span></dt><dd><p>
  33. A user-supplied function that is declared as taking no argument and
  34. returning type <code class="literal">event_trigger</code>.
  35. </p><p>
  36. In the syntax of <code class="literal">CREATE EVENT TRIGGER</code>, the keywords
  37. <code class="literal">FUNCTION</code> and <code class="literal">PROCEDURE</code> are
  38. equivalent, but the referenced function must in any case be a function,
  39. not a procedure. The use of the keyword <code class="literal">PROCEDURE</code>
  40. here is historical and deprecated.
  41. </p></dd></dl></div></div><div class="refsect1" id="SQL-CREATEEVENTTRIGGER-NOTES"><h2>Notes</h2><p>
  42. Only superusers can create event triggers.
  43. </p><p>
  44. 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
  45. database so much that you can't even drop the trigger, restart in
  46. single-user mode and you'll be able to do that.
  47. </p></div><div class="refsect1" id="SQL-CREATEEVENTTRIGGER-EXAMPLES"><h2>Examples</h2><p>
  48. Forbid the execution of any <a class="link" href="ddl.html" title="Chapter 5. Data Definition">DDL</a> command:
  49. </p><pre class="programlisting">
  50. CREATE OR REPLACE FUNCTION abort_any_command()
  51. RETURNS event_trigger
  52. LANGUAGE plpgsql
  53. AS $$
  54. BEGIN
  55. RAISE EXCEPTION 'command % is disabled', tg_tag;
  56. END;
  57. $$;
  58. CREATE EVENT TRIGGER abort_ddl ON ddl_command_start
  59. EXECUTE FUNCTION abort_any_command();
  60. </pre></div><div class="refsect1" id="SQL-CREATEEVENTTRIGGER-COMPATIBILITY"><h2>Compatibility</h2><p>
  61. There is no <code class="command">CREATE EVENT TRIGGER</code> statement in the
  62. SQL standard.
  63. </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>
上海开阖软件有限公司 沪ICP备12045867号-1