{"Entry":{"collection":"sql","key":"create-event-trigger","name":"CREATE EVENT TRIGGER","aliases":["createeventtrigger"],"metadata":{"aliases":["createeventtrigger"],"changed_in":["11"],"changes":[{"from":"9.2","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"added","synopsis":null,"to":"9.3"},{"from":"9.4","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["parameters"],"removed":[]},"status":"changed","synopsis":null,"to":"9.5"},{"from":"9.5","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","parameters"],"removed":[]},"status":"changed","synopsis":null,"to":"9.6"},{"from":"9.6","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","parameters"],"removed":[]},"status":"changed","synopsis":null,"to":"10"},{"from":"10","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","parameters","examples"],"removed":[]},"status":"changed","synopsis":{"added":["EXECUTE { FUNCTION | PROCEDURE } function_name()"],"removed":[]},"to":"11"},{"from":"11","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","parameters"],"removed":[]},"status":"changed","synopsis":null,"to":"12"},{"from":"13","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","parameters"],"removed":[]},"status":"changed","synopsis":null,"to":"14"},{"from":"16","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":["description","parameters","notes"],"removed":[]},"status":"changed","synopsis":null,"to":"17"}],"content_hash":"913de76338cf3acc5b53c7659c71e782632cc6fe95dd570f37277f876bba6f61","derived_content_hash":"fb04f25caed3af60a1f0f1b58d0ab58dd3046c12d9e21e3d6ee34e72bb36869a","editorial":{},"first_version":"9.3","group":"trigger","imported_at":"2026-09-30T17:43:38.322244+08:00","last_version":"20","name":"CREATE EVENT TRIGGER","object":"EVENT TRIGGER","position":6001,"present_in":["9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"purpose":"define a new event trigger","purpose_zh":"","related":["alter-event-trigger","drop-event-trigger","create-function"],"repair_provenance":{"original_source_revision":"a709ab85","receipt_sha256":"cdf59fc10e9dadd8192a2df0bad1ee08ba8e6d7a0bdd247085f190d69a1c5b3f","repair":"wiki-repair-20261023"},"slug":"create-event-trigger","source_rev":"wiki-repair-20261023:12d2c785bfae285482b786d6e184a7c8596bbfc860c745a7cf2a76d4686ba5c6","synopsis":"CREATE EVENT TRIGGER name\nON event\n[ WHEN filter_variable IN (filter_value [, ... ]) [ AND ... ] ]\nEXECUTE { FUNCTION | PROCEDURE } function_name()","verb":"CREATE"}},"Definition":{"Collection":"sql","Key":"create-event-trigger","SourceDatabase":"center","Version":"18","SourceTable":"sqlcmd","SourceKey":"create-event-trigger","SourceRevision":"wiki-repair-20261023:12d2c785bfae285482b786d6e184a7c8596bbfc860c745a7cf2a76d4686ba5c6","Facts":{"anchor":"SQL-CREATEEVENTTRIGGER","description_zh":"定义一个新的事件触发器","description_zh_html":"\u003cpre\u003eCREATE EVENT TRIGGER name\nON event\n[ WHEN filter_variable IN (filter_value [, ... ]) [ AND ... ] ]\nEXECUTE { FUNCTION | PROCEDURE } function_name()\u003c/pre\u003e\u003csection\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\n\u003ccode class=\"command\"\u003eCREATE EVENT TRIGGER\u003c/code\u003e 创建一个新的事件触发器。每当指定的事件发生，并且与该触发器关联的 \u003ccode class=\"literal\"\u003eWHEN\u003c/code\u003e 条件（如果有）得到满足时，就会执行该触发器函数。有关事件触发器的一般性介绍，见\u003ca class=\"xref\" href=\"/zh/docs/18/event-triggers.html\" title=\"第 38 章 事件触发器\"\u003e第 38 章\u003c/a\u003e。创建事件触发器的用户将成为其所有者。\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e参数\u003c/h2\u003e\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt id=\"ZH18-AUTO-CREATE_EVENT_TRIGGER-VARLISTENTRY-1\"\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      要赋予新触发器的名称。该名称在数据库内必须唯一。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt id=\"ZH18-AUTO-CREATE_EVENT_TRIGGER-VARLISTENTRY-2\"\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eevent\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      触发对给定函数调用的事件名称。有关事件名称的更多信息，见\u003ca class=\"xref\" href=\"/zh/docs/18/event-trigger-definition.html\" title=\"38.1. 事件触发器行为概述\"\u003e第 38.1 节\u003c/a\u003e。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt id=\"ZH18-AUTO-CREATE_EVENT_TRIGGER-VARLISTENTRY-3\"\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      用于过滤事件的变量名称。这样可以将触发器限定为只在原本支持的部分情形下触发。当前唯一支持的\n      \u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e\n      是 \u003ccode class=\"literal\"\u003eTAG\u003c/code\u003e。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt id=\"ZH18-AUTO-CREATE_EVENT_TRIGGER-VARLISTENTRY-4\"\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_value\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      与相关 \u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e\n      关联的一组值；当其取值属于该列表时，触发器就会被触发。对于\n      \u003ccode class=\"literal\"\u003eTAG\u003c/code\u003e，这表示一组命令标签（例如\n      \u003ccode class=\"literal\"\u003e'DROP FUNCTION'\u003c/code\u003e）。\n     \u003c/p\u003e\u003c/dd\u003e\u003cdt id=\"ZH18-AUTO-CREATE_EVENT_TRIGGER-VARLISTENTRY-5\"\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003efunction_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e \u003c/dt\u003e\u003cdd\u003e\u003cp\u003e\n      由用户提供的函数，声明为不接受参数并返回类型\n      \u003ccode class=\"literal\"\u003eevent_trigger\u003c/code\u003e。\n     \u003c/p\u003e\u003cp\u003e\n      在 \u003ccode class=\"literal\"\u003eCREATE EVENT TRIGGER\u003c/code\u003e 的语法中，关键字\n      \u003ccode class=\"literal\"\u003eFUNCTION\u003c/code\u003e 和 \u003ccode class=\"literal\"\u003ePROCEDURE\u003c/code\u003e 是等效的，但被引用的对象无论如何都必须是函数，而不是过程。这里使用关键字\n      \u003ccode class=\"literal\"\u003ePROCEDURE\u003c/code\u003e 属于历史遗留做法，现已弃用。\n     \u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e注解\u003c/h2\u003e\u003cp\u003e\n   只有超级用户能创建事件触发器。\n  \u003c/p\u003e\u003cp\u003e\n   在单用户模式（见 \u003ca class=\"xref\" href=\"/zh/docs/18/app-postgres.html\" title=\"postgres\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epostgres\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e）下，以及当 \u003ca class=\"xref\" href=\"/zh/docs/18/runtime-config-client.html#GUC-EVENT-TRIGGERS\"\u003eevent_triggers\u003c/a\u003e 被设置为 \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e 时，事件触发器都会被禁用。如果某个错误的事件触发器使数据库严重不可用，甚至无法删除该触发器，可以在将 \u003ca class=\"xref\" href=\"/zh/docs/18/runtime-config-client.html#GUC-EVENT-TRIGGERS\"\u003eevent_triggers\u003c/a\u003e 设置为 \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e 的情况下重启，以临时禁用事件触发器，或者以单用户模式重启，这样就可以删除它。\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e示例\u003c/h2\u003e\u003cp\u003e\n   禁止执行任何 \u003ca class=\"link\" href=\"/zh/docs/18/ddl.html\" title=\"第 5 章 数据定义\"\u003eDDL\u003c/a\u003e 命令：\n\n\u003c/p\u003e\u003cpre class=\"programlisting\"\u003e\nCREATE OR REPLACE FUNCTION abort_any_command()\n  RETURNS event_trigger\n LANGUAGE plpgsql\n  AS $$\nBEGIN\n  RAISE EXCEPTION 'command % is disabled', tg_tag;\nEND;\n$$;\n\nCREATE EVENT TRIGGER abort_ddl ON ddl_command_start\n   EXECUTE FUNCTION abort_any_command();\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e兼容性\u003c/h2\u003e\u003cp\u003e\n   在 SQL 标准中没有\n   \u003ccode class=\"command\"\u003eCREATE EVENT TRIGGER\u003c/code\u003e 语句。\n  \u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e另见\u003c/h2\u003e\u003cspan class=\"simplelist\"\u003e\u003ca class=\"xref\" href=\"/zh/docs/18/sql-altereventtrigger.html\" title=\"ALTER EVENT TRIGGER\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER EVENT TRIGGER\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/zh/docs/18/sql-dropeventtrigger.html\" title=\"DROP EVENT TRIGGER\"\u003e\u003cspan class=\"refentrytitle\"\u003eDROP EVENT TRIGGER\u003c/span\u003e\u003c/a\u003e, \u003ca class=\"xref\" href=\"/zh/docs/18/sql-createfunction.html\" title=\"CREATE FUNCTION\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FUNCTION\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","file":"sql-createeventtrigger.html","lang":"en","name":"CREATE EVENT TRIGGER","purpose":"define a new event trigger","purpose_zh":"定义一个新的事件触发器","related":["alter-event-trigger","drop-event-trigger","create-function"],"sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eCREATE EVENT TRIGGER\u003c/code\u003e creates a new event trigger. Whenever the designated event occurs and the \u003ccode class=\"literal\"\u003eWHEN\u003c/code\u003e condition associated with the trigger, if any, is satisfied, the trigger function will be executed. For a general introduction to event triggers, see \u003ca href=\"/docs/18/event-triggers.html\" title=\"Chapter 38. Event Triggers\"\u003eChapter 38\u003c/a\u003e. The user who creates an event trigger becomes its owner.\u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe name to give the new trigger. This name must be unique within the database.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eevent\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe name of the event that triggers a call to the given function. See \u003ca href=\"/docs/18/event-trigger-definition.html\" title=\"38.1. Overview of Event Trigger Behavior\"\u003eSection 38.1\u003c/a\u003e for more information on event names.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe 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 \u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e is \u003ccode class=\"literal\"\u003eTAG\u003c/code\u003e.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_value\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eA list of values for the associated \u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e for which the trigger should fire. For \u003ccode class=\"literal\"\u003eTAG\u003c/code\u003e, this means a list of command tags (e.g., \u003ccode class=\"literal\"\u003e'DROP FUNCTION'\u003c/code\u003e).\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003efunction_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eA user-supplied function that is declared as taking no argument and returning type \u003ccode class=\"literal\"\u003eevent_trigger\u003c/code\u003e.\u003c/p\u003e\u003cp\u003eIn the syntax of \u003ccode class=\"literal\"\u003eCREATE EVENT TRIGGER\u003c/code\u003e, the keywords \u003ccode class=\"literal\"\u003eFUNCTION\u003c/code\u003e and \u003ccode class=\"literal\"\u003ePROCEDURE\u003c/code\u003e are equivalent, but the referenced function must in any case be a function, not a procedure. The use of the keyword \u003ccode class=\"literal\"\u003ePROCEDURE\u003c/code\u003e here is historical and deprecated.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003eOnly superusers can create event triggers.\u003c/p\u003e\u003cp\u003eEvent triggers are disabled in single-user mode (see \u003ca href=\"/docs/18/app-postgres.html\" title=\"postgres\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epostgres\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e) as well as when \u003ca href=\"/docs/18/runtime-config-client.html#GUC-EVENT-TRIGGERS\"\u003eevent_triggers\u003c/a\u003e is set to \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e. If an erroneous event trigger disables the database so much that you can't even drop the trigger, restart with \u003ca href=\"/docs/18/runtime-config-client.html#GUC-EVENT-TRIGGERS\"\u003eevent_triggers\u003c/a\u003e set to \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e to temporarily disable event triggers, or in single-user mode, and you'll be able to do that.\u003c/p\u003e","key":"notes","title":"Notes"},{"html":"\u003cp\u003eForbid the execution of any \u003ca href=\"/docs/18/ddl.html\" title=\"Chapter 5. Data Definition\"\u003eDDL\u003c/a\u003e command:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eCREATE OR REPLACE FUNCTION abort_any_command()\n  RETURNS event_trigger\n LANGUAGE plpgsql\n  AS $$\nBEGIN\n  RAISE EXCEPTION 'command % is disabled', tg_tag;\nEND;\n$$;\n\nCREATE EVENT TRIGGER abort_ddl ON ddl_command_start\n   EXECUTE FUNCTION abort_any_command();\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003eThere is no \u003ccode class=\"command\"\u003eCREATE EVENT TRIGGER\u003c/code\u003e statement in the SQL standard.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/alter-event-trigger/?v=18\" title=\"ALTER EVENT TRIGGER\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER EVENT TRIGGER\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-event-trigger/?v=18\" title=\"DROP EVENT TRIGGER\"\u003e\u003cspan class=\"refentrytitle\"\u003eDROP EVENT TRIGGER\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/create-function/?v=18\" title=\"CREATE FUNCTION\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FUNCTION\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","slug":"18","synopsis_html":"CREATE EVENT TRIGGER \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\n    ON \u003cem class=\"replaceable\"\u003e\u003ccode\u003eevent\u003c/code\u003e\u003c/em\u003e\n    [ WHEN \u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e IN (\u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_value\u003c/code\u003e\u003c/em\u003e [, ... ]) [ AND ... ] ]\n    EXECUTE { FUNCTION | PROCEDURE } \u003cem class=\"replaceable\"\u003e\u003ccode\u003efunction_name\u003c/code\u003e\u003c/em\u003e()","synopsis_text":"CREATE EVENT TRIGGER name\nON event\n[ WHEN filter_variable IN (filter_value [, ... ]) [ AND ... ] ]\nEXECUTE { FUNCTION | PROCEDURE } function_name()","translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/sql-createeventtrigger.html","sha256":"6049d1b38a9c5c9c18072005db53ee878bd0af6ee8ff827341a228a74c3dc849"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"zh_from":"same-version-pgdoc"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"create-event-trigger","SourceDatabase":"center","Version":"18","Locale":"en","Title":"CREATE EVENT TRIGGER","Summary":"define a new event trigger","BodyHTML":"\u003cpre\u003eCREATE EVENT TRIGGER name\nON event\n[ WHEN filter_variable IN (filter_value [, ... ]) [ AND ... ] ]\nEXECUTE { FUNCTION | PROCEDURE } function_name()\u003c/pre\u003e\u003csection\u003e\u003ch2\u003eDescription\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eCREATE EVENT TRIGGER\u003c/code\u003e creates a new event trigger. Whenever the designated event occurs and the \u003ccode\u003eWHEN\u003c/code\u003e condition associated with the trigger, if any, is satisfied, the trigger function will be executed. For a general introduction to event triggers, see \u003ca href=\"/docs/18/event-triggers.html\" rel=\"nofollow\"\u003eChapter 38\u003c/a\u003e. The user who creates an event trigger becomes its owner.\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eParameters\u003c/h2\u003e\u003cdiv\u003e\u003cdl\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe name to give the new trigger. This name must be unique within the database.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003eevent\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe name of the event that triggers a call to the given function. See \u003ca href=\"/docs/18/event-trigger-definition.html\" rel=\"nofollow\"\u003eSection 38.1\u003c/a\u003e for more information on event names.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe 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 \u003cem\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e is \u003ccode\u003eTAG\u003c/code\u003e.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003efilter_value\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eA list of values for the associated \u003cem\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e for which the trigger should fire. For \u003ccode\u003eTAG\u003c/code\u003e, this means a list of command tags (e.g., \u003ccode\u003e\u0026#39;DROP FUNCTION\u0026#39;\u003c/code\u003e).\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003efunction_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eA user-supplied function that is declared as taking no argument and returning type \u003ccode\u003eevent_trigger\u003c/code\u003e.\u003c/p\u003e\u003cp\u003eIn the syntax of \u003ccode\u003eCREATE EVENT TRIGGER\u003c/code\u003e, the keywords \u003ccode\u003eFUNCTION\u003c/code\u003e and \u003ccode\u003ePROCEDURE\u003c/code\u003e are equivalent, but the referenced function must in any case be a function, not a procedure. The use of the keyword \u003ccode\u003ePROCEDURE\u003c/code\u003e here is historical and deprecated.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eNotes\u003c/h2\u003e\u003cp\u003eOnly superusers can create event triggers.\u003c/p\u003e\u003cp\u003eEvent triggers are disabled in single-user mode (see \u003ca href=\"/docs/18/app-postgres.html\" title=\"postgres\" rel=\"nofollow\"\u003e\u003cspan\u003e\u003cspan\u003epostgres\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e) as well as when \u003ca href=\"/docs/18/runtime-config-client.html#GUC-EVENT-TRIGGERS\" rel=\"nofollow\"\u003eevent_triggers\u003c/a\u003e is set to \u003ccode\u003efalse\u003c/code\u003e. If an erroneous event trigger disables the database so much that you can\u0026#39;t even drop the trigger, restart with \u003ca href=\"/docs/18/runtime-config-client.html#GUC-EVENT-TRIGGERS\" rel=\"nofollow\"\u003eevent_triggers\u003c/a\u003e set to \u003ccode\u003efalse\u003c/code\u003e to temporarily disable event triggers, or in single-user mode, and you\u0026#39;ll be able to do that.\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eExamples\u003c/h2\u003e\u003cp\u003eForbid the execution of any \u003ca href=\"/docs/18/ddl.html\" rel=\"nofollow\"\u003eDDL\u003c/a\u003e command:\u003c/p\u003e\u003cpre\u003eCREATE OR REPLACE FUNCTION abort_any_command()\n  RETURNS event_trigger\n LANGUAGE plpgsql\n  AS $$\nBEGIN\n  RAISE EXCEPTION \u0026#39;command % is disabled\u0026#39;, tg_tag;\nEND;\n$$;\n\nCREATE EVENT TRIGGER abort_ddl ON ddl_command_start\n   EXECUTE FUNCTION abort_any_command();\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eCompatibility\u003c/h2\u003e\u003cp\u003eThere is no \u003ccode\u003eCREATE EVENT TRIGGER\u003c/code\u003e statement in the SQL standard.\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003eSee Also\u003c/h2\u003e\u003cspan\u003e\u003ca href=\"/wiki/sql/alter-event-trigger/?v=18\" title=\"ALTER EVENT TRIGGER\" rel=\"nofollow\"\u003e\u003cspan\u003eALTER EVENT TRIGGER\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-event-trigger/?v=18\" title=\"DROP EVENT TRIGGER\" rel=\"nofollow\"\u003e\u003cspan\u003eDROP EVENT TRIGGER\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/create-function/?v=18\" title=\"CREATE FUNCTION\" rel=\"nofollow\"\u003e\u003cspan\u003eCREATE FUNCTION\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","SourceRevision":"wiki-repair-20261023:12d2c785bfae285482b786d6e184a7c8596bbfc860c745a7cf2a76d4686ba5c6","ContentHash":"fe39bdbc1cf68dc3da4ed3795501890554674d8ad99514058f4c2d3fda61e32c","Payload":{"related":["alter-event-trigger","drop-event-trigger","create-function"],"sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eCREATE EVENT TRIGGER\u003c/code\u003e creates a new event trigger. Whenever the designated event occurs and the \u003ccode class=\"literal\"\u003eWHEN\u003c/code\u003e condition associated with the trigger, if any, is satisfied, the trigger function will be executed. For a general introduction to event triggers, see \u003ca href=\"/docs/18/event-triggers.html\" title=\"Chapter 38. Event Triggers\"\u003eChapter 38\u003c/a\u003e. The user who creates an event trigger becomes its owner.\u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe name to give the new trigger. This name must be unique within the database.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003eevent\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe name of the event that triggers a call to the given function. See \u003ca href=\"/docs/18/event-trigger-definition.html\" title=\"38.1. Overview of Event Trigger Behavior\"\u003eSection 38.1\u003c/a\u003e for more information on event names.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe 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 \u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e is \u003ccode class=\"literal\"\u003eTAG\u003c/code\u003e.\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_value\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eA list of values for the associated \u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e for which the trigger should fire. For \u003ccode class=\"literal\"\u003eTAG\u003c/code\u003e, this means a list of command tags (e.g., \u003ccode class=\"literal\"\u003e'DROP FUNCTION'\u003c/code\u003e).\u003c/p\u003e\u003c/dd\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003efunction_name\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eA user-supplied function that is declared as taking no argument and returning type \u003ccode class=\"literal\"\u003eevent_trigger\u003c/code\u003e.\u003c/p\u003e\u003cp\u003eIn the syntax of \u003ccode class=\"literal\"\u003eCREATE EVENT TRIGGER\u003c/code\u003e, the keywords \u003ccode class=\"literal\"\u003eFUNCTION\u003c/code\u003e and \u003ccode class=\"literal\"\u003ePROCEDURE\u003c/code\u003e are equivalent, but the referenced function must in any case be a function, not a procedure. The use of the keyword \u003ccode class=\"literal\"\u003ePROCEDURE\u003c/code\u003e here is historical and deprecated.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003eOnly superusers can create event triggers.\u003c/p\u003e\u003cp\u003eEvent triggers are disabled in single-user mode (see \u003ca href=\"/docs/18/app-postgres.html\" title=\"postgres\"\u003e\u003cspan class=\"refentrytitle\"\u003e\u003cspan class=\"application\"\u003epostgres\u003c/span\u003e\u003c/span\u003e\u003c/a\u003e) as well as when \u003ca href=\"/docs/18/runtime-config-client.html#GUC-EVENT-TRIGGERS\"\u003eevent_triggers\u003c/a\u003e is set to \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e. If an erroneous event trigger disables the database so much that you can't even drop the trigger, restart with \u003ca href=\"/docs/18/runtime-config-client.html#GUC-EVENT-TRIGGERS\"\u003eevent_triggers\u003c/a\u003e set to \u003ccode class=\"literal\"\u003efalse\u003c/code\u003e to temporarily disable event triggers, or in single-user mode, and you'll be able to do that.\u003c/p\u003e","key":"notes","title":"Notes"},{"html":"\u003cp\u003eForbid the execution of any \u003ca href=\"/docs/18/ddl.html\" title=\"Chapter 5. Data Definition\"\u003eDDL\u003c/a\u003e command:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eCREATE OR REPLACE FUNCTION abort_any_command()\n  RETURNS event_trigger\n LANGUAGE plpgsql\n  AS $$\nBEGIN\n  RAISE EXCEPTION 'command % is disabled', tg_tag;\nEND;\n$$;\n\nCREATE EVENT TRIGGER abort_ddl ON ddl_command_start\n   EXECUTE FUNCTION abort_any_command();\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003eThere is no \u003ccode class=\"command\"\u003eCREATE EVENT TRIGGER\u003c/code\u003e statement in the SQL standard.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/alter-event-trigger/?v=18\" title=\"ALTER EVENT TRIGGER\"\u003e\u003cspan class=\"refentrytitle\"\u003eALTER EVENT TRIGGER\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/drop-event-trigger/?v=18\" title=\"DROP EVENT TRIGGER\"\u003e\u003cspan class=\"refentrytitle\"\u003eDROP EVENT TRIGGER\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/create-function/?v=18\" title=\"CREATE FUNCTION\"\u003e\u003cspan class=\"refentrytitle\"\u003eCREATE FUNCTION\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","synopsis_html":"CREATE EVENT TRIGGER \u003cem class=\"replaceable\"\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/em\u003e\n    ON \u003cem class=\"replaceable\"\u003e\u003ccode\u003eevent\u003c/code\u003e\u003c/em\u003e\n    [ WHEN \u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e IN (\u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_value\u003c/code\u003e\u003c/em\u003e [, ... ]) [ AND ... ] ]\n    EXECUTE { FUNCTION | PROCEDURE } \u003cem class=\"replaceable\"\u003e\u003ccode\u003efunction_name\u003c/code\u003e\u003c/em\u003e()","synopsis_text":"CREATE EVENT TRIGGER name\nON event\n[ WHEN filter_variable IN (filter_value [, ... ]) [ AND ... ] ]\nEXECUTE { FUNCTION | PROCEDURE } function_name()"}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
