2 .\" Title: CREATE EVENT TRIGGER
3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "CREATE EVENT TRIGGER" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 CREATE_EVENT_TRIGGER \- define a new event trigger
35 CREATE EVENT TRIGGER \fIname\fR
37 [ WHEN \fIfilter_variable\fR IN (\fIfilter_value\fR [, \&.\&.\&. ]) [ AND \&.\&.\&. ] ]
38 EXECUTE { FUNCTION | PROCEDURE } \fIfunction_name\fR()
42 \fBCREATE EVENT TRIGGER\fR
43 creates a new event trigger\&. Whenever the designated event occurs and the
45 condition associated with the trigger, if any, is satisfied, the trigger function will be executed\&. For a general introduction to event triggers, see
46 Chapter\ \&38\&. The user who creates an event trigger becomes its owner\&.
51 The name to give the new trigger\&. This name must be unique within the database\&.
56 The name of the event that triggers a call to the given function\&. See
58 for more information on event names\&.
63 The 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
71 A list of values for the associated
73 for which the trigger should fire\&. For
74 TAG, this means a list of command tags (e\&.g\&.,
75 \*(AqDROP FUNCTION\*(Aq)\&.
80 A user\-supplied function that is declared as taking no argument and returning type
84 CREATE EVENT TRIGGER, the keywords
88 are equivalent, but the referenced function must in any case be a function, not a procedure\&. The use of the keyword
90 here is historical and deprecated\&.
94 Only superusers can create event triggers\&.
96 Event triggers are disabled in single\-user mode (see
97 \fBpostgres\fR(1)) as well as when
100 false\&. If an erroneous event trigger disables the database so much that you can\*(Aqt even drop the trigger, restart with
104 to temporarily disable event triggers, or in single\-user mode, and you\*(Aqll be able to do that\&.
107 Forbid the execution of any
115 CREATE OR REPLACE FUNCTION abort_any_command()
116 RETURNS event_trigger
120 RAISE EXCEPTION \*(Aqcommand % is disabled\*(Aq, tg_tag;
124 CREATE EVENT TRIGGER abort_ddl ON ddl_command_start
125 EXECUTE FUNCTION abort_any_command();
133 \fBCREATE EVENT TRIGGER\fR
134 statement in the SQL standard\&.
136 ALTER EVENT TRIGGER (\fBALTER_EVENT_TRIGGER\fR(7)), DROP EVENT TRIGGER (\fBDROP_EVENT_TRIGGER\fR(7)), CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))