{"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","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"],"slug":"create-event-trigger","source_rev":"a709ab85","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":"a709ab85","Facts":{"anchor":"SQL-CREATEEVENTTRIGGER","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()"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"create-event-trigger","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"CREATE EVENT TRIGGER","Summary":"定义一个新的事件触发器","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\u003e描述\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eCREATE EVENT TRIGGER\u003c/code\u003e创建一个新的事件触发器。每当指定的事件发生，并且与该触发器关联的\u003ccode\u003eWHEN\u003c/code\u003e条件（如果有）得到满足时，就会执行该触发器函数。有关事件触发器的一般性介绍，见\u003ca href=\"/docs/18/event-triggers.html\" rel=\"nofollow\"\u003e第 38 章\u003c/a\u003e。创建事件触发器的用户将成为其所有者。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e参数\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\u003e要赋予新触发器的名称。该名称在数据库内必须唯一。\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\u003e触发对给定函数调用的事件名称。有关事件名称的更多信息，见\u003ca href=\"/docs/18/event-trigger-definition.html\" rel=\"nofollow\"\u003e第 38.1 节\u003c/a\u003e。\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\u003e用于过滤事件的变量名称。这样可以将触发器限定为只在原本支持的部分情形下触发。当前唯一支持的 \u003cem\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e 是\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\u003e与相关\u003cem\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e 关联的一组值；当其取值属于该列表时，触发器就会被触发。对于 \u003ccode\u003eTAG\u003c/code\u003e，这表示一组命令标签（例如 \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\u003e由用户提供的函数，声明为不接受参数并返回类型 \u003ccode\u003eevent_trigger\u003c/code\u003e。\u003c/p\u003e\u003cp\u003e在\u003ccode\u003eCREATE EVENT TRIGGER\u003c/code\u003e的语法中，关键字 \u003ccode\u003eFUNCTION\u003c/code\u003e和\u003ccode\u003ePROCEDURE\u003c/code\u003e是等效的，但被引用的对象无论如何都必须是函数，而不是过程。这里使用关键字 \u003ccode\u003ePROCEDURE\u003c/code\u003e属于历史遗留做法，现已弃用。\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e注解\u003c/h2\u003e\u003cp\u003e只有超级用户能创建事件触发器。\u003c/p\u003e\u003cp\u003e在单用户模式（见\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）下，以及当\u003ca href=\"/docs/18/runtime-config-client.html#GUC-EVENT-TRIGGERS\" rel=\"nofollow\"\u003eevent_triggers\u003c/a\u003e被设置为\u003ccode\u003efalse\u003c/code\u003e时，事件触发器都会被禁用。如果某个错误的事件触发器使数据库严重不可用，甚至无法删除该触发器，可以在将\u003ca href=\"/docs/18/runtime-config-client.html#GUC-EVENT-TRIGGERS\" rel=\"nofollow\"\u003eevent_triggers\u003c/a\u003e设置为\u003ccode\u003efalse\u003c/code\u003e的情况下重启，以临时禁用事件触发器，或者以单用户模式重启，这样就可以删除它。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e示例\u003c/h2\u003e\u003cp\u003e禁止执行任何\u003ca href=\"/docs/18/ddl.html\" rel=\"nofollow\"\u003eDDL\u003c/a\u003e命令：\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\u003e兼容性\u003c/h2\u003e\u003cp\u003e在 SQL 标准中没有 \u003ccode\u003eCREATE EVENT TRIGGER\u003c/code\u003e语句。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e另见\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":"1b5ca64c","ContentHash":"6452cf4db25a847e9a9df41fc562319c320ad7196508a0e1c17e9ba2cee09919","Payload":{"purpose_zh":"定义一个新的事件触发器","sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eCREATE EVENT TRIGGER\u003c/code\u003e创建一个新的事件触发器。每当指定的事件发生，并且与该触发器关联的\u003ccode class=\"literal\"\u003eWHEN\u003c/code\u003e条件（如果有）得到满足时，就会执行该触发器函数。有关事件触发器的一般性介绍，见\u003ca href=\"/docs/18/event-triggers.html\" title=\"第 38 章 事件触发器\"\u003e第 38 章\u003c/a\u003e。创建事件触发器的用户将成为其所有者。\u003c/p\u003e","key":"description","title":"描述"},{"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\u003e要赋予新触发器的名称。该名称在数据库内必须唯一。\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\u003e触发对给定函数调用的事件名称。有关事件名称的更多信息，见\u003ca href=\"/docs/18/event-trigger-definition.html\" title=\"38.1. 事件触发器行为概述\"\u003e第 38.1 节\u003c/a\u003e。\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\u003e用于过滤事件的变量名称。这样可以将触发器限定为只在原本支持的部分情形下触发。当前唯一支持的 \u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e 是\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\u003e与相关\u003cem class=\"replaceable\"\u003e\u003ccode\u003efilter_variable\u003c/code\u003e\u003c/em\u003e 关联的一组值；当其取值属于该列表时，触发器就会被触发。对于 \u003ccode class=\"literal\"\u003eTAG\u003c/code\u003e，这表示一组命令标签（例如 \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\u003e由用户提供的函数，声明为不接受参数并返回类型 \u003ccode class=\"literal\"\u003eevent_trigger\u003c/code\u003e。\u003c/p\u003e\u003cp\u003e在\u003ccode class=\"literal\"\u003eCREATE EVENT TRIGGER\u003c/code\u003e的语法中，关键字 \u003ccode class=\"literal\"\u003eFUNCTION\u003c/code\u003e和\u003ccode class=\"literal\"\u003ePROCEDURE\u003c/code\u003e是等效的，但被引用的对象无论如何都必须是函数，而不是过程。这里使用关键字 \u003ccode class=\"literal\"\u003ePROCEDURE\u003c/code\u003e属于历史遗留做法，现已弃用。\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"参数"},{"html":"\u003cp\u003e只有超级用户能创建事件触发器。\u003c/p\u003e\u003cp\u003e在单用户模式（见\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）下，以及当\u003ca href=\"/docs/18/runtime-config-client.html#GUC-EVENT-TRIGGERS\"\u003eevent_triggers\u003c/a\u003e被设置为\u003ccode class=\"literal\"\u003efalse\u003c/code\u003e时，事件触发器都会被禁用。如果某个错误的事件触发器使数据库严重不可用，甚至无法删除该触发器，可以在将\u003ca href=\"/docs/18/runtime-config-client.html#GUC-EVENT-TRIGGERS\"\u003eevent_triggers\u003c/a\u003e设置为\u003ccode class=\"literal\"\u003efalse\u003c/code\u003e的情况下重启，以临时禁用事件触发器，或者以单用户模式重启，这样就可以删除它。\u003c/p\u003e","key":"notes","title":"注解"},{"html":"\u003cp\u003e禁止执行任何\u003ca href=\"/docs/18/ddl.html\" title=\"第 5 章 数据定义\"\u003eDDL\u003c/a\u003e命令：\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":"示例"},{"html":"\u003cp\u003e在 SQL 标准中没有 \u003ccode class=\"command\"\u003eCREATE EVENT TRIGGER\u003c/code\u003e语句。\u003c/p\u003e","key":"compatibility","title":"兼容性"},{"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":"另见"}],"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":"zh-Hans","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}
