]> begriffs open source - ai-pg/blob - full-docs/man7/CREATE_EVENT_TRIGGER.7
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man7 / CREATE_EVENT_TRIGGER.7
1 '\" t
2 .\"     Title: CREATE EVENT TRIGGER
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 CREATE_EVENT_TRIGGER \- define a new event trigger
32 .SH "SYNOPSIS"
33 .sp
34 .nf
35 CREATE EVENT TRIGGER \fIname\fR
36     ON \fIevent\fR
37     [ WHEN \fIfilter_variable\fR IN (\fIfilter_value\fR [, \&.\&.\&. ]) [ AND \&.\&.\&. ] ]
38     EXECUTE { FUNCTION | PROCEDURE } \fIfunction_name\fR()
39 .fi
40 .SH "DESCRIPTION"
41 .PP
42 \fBCREATE EVENT TRIGGER\fR
43 creates a new event trigger\&. Whenever the designated event occurs and the
44 WHEN
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\&.
47 .SH "PARAMETERS"
48 .PP
49 \fIname\fR
50 .RS 4
51 The name to give the new trigger\&. This name must be unique within the database\&.
52 .RE
53 .PP
54 \fIevent\fR
55 .RS 4
56 The name of the event that triggers a call to the given function\&. See
57 Section\ \&38.1
58 for more information on event names\&.
59 .RE
60 .PP
61 \fIfilter_variable\fR
62 .RS 4
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
64 \fIfilter_variable\fR
65 is
66 TAG\&.
67 .RE
68 .PP
69 \fIfilter_value\fR
70 .RS 4
71 A list of values for the associated
72 \fIfilter_variable\fR
73 for which the trigger should fire\&. For
74 TAG, this means a list of command tags (e\&.g\&.,
75 \*(AqDROP FUNCTION\*(Aq)\&.
76 .RE
77 .PP
78 \fIfunction_name\fR
79 .RS 4
80 A user\-supplied function that is declared as taking no argument and returning type
81 event_trigger\&.
82 .sp
83 In the syntax of
84 CREATE EVENT TRIGGER, the keywords
85 FUNCTION
86 and
87 PROCEDURE
88 are equivalent, but the referenced function must in any case be a function, not a procedure\&. The use of the keyword
89 PROCEDURE
90 here is historical and deprecated\&.
91 .RE
92 .SH "NOTES"
93 .PP
94 Only superusers can create event triggers\&.
95 .PP
96 Event triggers are disabled in single\-user mode (see
97 \fBpostgres\fR(1)) as well as when
98 event_triggers
99 is set to
100 false\&. If an erroneous event trigger disables the database so much that you can\*(Aqt even drop the trigger, restart with
101 event_triggers
102 set to
103 false
104 to temporarily disable event triggers, or in single\-user mode, and you\*(Aqll be able to do that\&.
105 .SH "EXAMPLES"
106 .PP
107 Forbid the execution of any
108 DDL
109 command:
110 .sp
111 .if n \{\
112 .RS 4
113 .\}
114 .nf
115 CREATE OR REPLACE FUNCTION abort_any_command()
116   RETURNS event_trigger
117  LANGUAGE plpgsql
118   AS $$
119 BEGIN
120   RAISE EXCEPTION \*(Aqcommand % is disabled\*(Aq, tg_tag;
121 END;
122 $$;
123
124 CREATE EVENT TRIGGER abort_ddl ON ddl_command_start
125    EXECUTE FUNCTION abort_any_command();
126 .fi
127 .if n \{\
128 .RE
129 .\}
130 .SH "COMPATIBILITY"
131 .PP
132 There is no
133 \fBCREATE EVENT TRIGGER\fR
134 statement in the SQL standard\&.
135 .SH "SEE ALSO"
136 ALTER EVENT TRIGGER (\fBALTER_EVENT_TRIGGER\fR(7)), DROP EVENT TRIGGER (\fBDROP_EVENT_TRIGGER\fR(7)), CREATE FUNCTION (\fBCREATE_FUNCTION\fR(7))