1CREATE EVENT TRIGGER(7) PostgreSQL 11.3 Documentation CREATE EVENT TRIGGER(7)
2
3
4
6 CREATE_EVENT_TRIGGER - define a new event trigger
7
9 CREATE EVENT TRIGGER name
10 ON event
11 [ WHEN filter_variable IN (filter_value [, ... ]) [ AND ... ] ]
12 EXECUTE { FUNCTION | PROCEDURE } function_name()
13
15 CREATE EVENT TRIGGER creates a new event trigger. Whenever the
16 designated event occurs and the WHEN condition associated with the
17 trigger, if any, is satisfied, the trigger function will be executed.
18 For a general introduction to event triggers, see Chapter 40. The user
19 who creates an event trigger becomes its owner.
20
22 name
23 The name to give the new trigger. This name must be unique within
24 the database.
25
26 event
27 The name of the event that triggers a call to the given function.
28 See Section 40.1 for more information on event names.
29
30 filter_variable
31 The name of a variable used to filter events. This makes it
32 possible to restrict the firing of the trigger to a subset of the
33 cases in which it is supported. Currently the only supported
34 filter_variable is TAG.
35
36 filter_value
37 A list of values for the associated filter_variable for which the
38 trigger should fire. For TAG, this means a list of command tags
39 (e.g. 'DROP FUNCTION').
40
41 function_name
42 A user-supplied function that is declared as taking no argument and
43 returning type event_trigger.
44
45 In the syntax of CREATE EVENT TRIGGER, the keywords FUNCTION and
46 PROCEDURE are equivalent, but the referenced function must in any
47 case be a function, not a procedure. The use of the keyword
48 PROCEDURE here is historical and deprecated.
49
51 Only superusers can create event triggers.
52
53 Event triggers are disabled in single-user mode (see postgres(1)). If
54 an erroneous event trigger disables the database so much that you can't
55 even drop the trigger, restart in single-user mode and you'll be able
56 to do that.
57
59 Forbid the execution of any DDL command:
60
61 CREATE OR REPLACE FUNCTION abort_any_command()
62 RETURNS event_trigger
63 LANGUAGE plpgsql
64 AS $$
65 BEGIN
66 RAISE EXCEPTION 'command % is disabled', tg_tag;
67 END;
68 $$;
69
70 CREATE EVENT TRIGGER abort_ddl ON ddl_command_start
71 EXECUTE FUNCTION abort_any_command();
72
74 There is no CREATE EVENT TRIGGER statement in the SQL standard.
75
77 ALTER EVENT TRIGGER (ALTER_EVENT_TRIGGER(7)), DROP EVENT TRIGGER
78 (DROP_EVENT_TRIGGER(7)), CREATE FUNCTION (CREATE_FUNCTION(7))
79
80
81
82PostgreSQL 11.3 2019 CREATE EVENT TRIGGER(7)