1CREATE EVENT TRIGGER(7) PostgreSQL 10.7 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 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 39. 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 39.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
46 Only superusers can create event triggers.
47
48 Event triggers are disabled in single-user mode (see postgres(1)). If
49 an erroneous event trigger disables the database so much that you can't
50 even drop the trigger, restart in single-user mode and you'll be able
51 to do that.
52
54 Forbid the execution of any DDL command:
55
56 CREATE OR REPLACE FUNCTION abort_any_command()
57 RETURNS event_trigger
58 LANGUAGE plpgsql
59 AS $$
60 BEGIN
61 RAISE EXCEPTION 'command % is disabled', tg_tag;
62 END;
63 $$;
64
65 CREATE EVENT TRIGGER abort_ddl ON ddl_command_start
66 EXECUTE PROCEDURE abort_any_command();
67
69 There is no CREATE EVENT TRIGGER statement in the SQL standard.
70
72 ALTER EVENT TRIGGER (ALTER_EVENT_TRIGGER(7)), DROP EVENT TRIGGER
73 (DROP_EVENT_TRIGGER(7)), CREATE FUNCTION (CREATE_FUNCTION(7))
74
75
76
77PostgreSQL 10.7 2019 CREATE EVENT TRIGGER(7)