4 CREATE EVENT TRIGGER — define a new event trigger
8 CREATE EVENT TRIGGER name
10 [ WHEN filter_variable IN (filter_value [, ... ]) [ AND ... ] ]
11 EXECUTE { FUNCTION | PROCEDURE } function_name()
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 38. The user
19 who creates an event trigger becomes its owner.
24 The name to give the new trigger. This name must be unique
28 The name of the event that triggers a call to the given
29 function. See Section 38.1 for more information on event names.
32 The name of a variable used to filter events. This makes it
33 possible to restrict the firing of the trigger to a subset of
34 the cases in which it is supported. Currently the only supported
35 filter_variable is TAG.
38 A list of values for the associated filter_variable for which
39 the trigger should fire. For TAG, this means a list of command
40 tags (e.g., 'DROP FUNCTION').
43 A user-supplied function that is declared as taking no argument
44 and returning type event_trigger.
46 In the syntax of CREATE EVENT TRIGGER, the keywords FUNCTION and
47 PROCEDURE are equivalent, but the referenced function must in
48 any case be a function, not a procedure. The use of the keyword
49 PROCEDURE here is historical and deprecated.
53 Only superusers can create event triggers.
55 Event triggers are disabled in single-user mode (see postgres) as well
56 as when event_triggers is set to false. If an erroneous event trigger
57 disables the database so much that you can't even drop the trigger,
58 restart with event_triggers set to false to temporarily disable event
59 triggers, or in single-user mode, and you'll be able to do that.
63 Forbid the execution of any DDL command:
64 CREATE OR REPLACE FUNCTION abort_any_command()
69 RAISE EXCEPTION 'command % is disabled', tg_tag;
73 CREATE EVENT TRIGGER abort_ddl ON ddl_command_start
74 EXECUTE FUNCTION abort_any_command();
78 There is no CREATE EVENT TRIGGER statement in the SQL standard.
82 ALTER EVENT TRIGGER, DROP EVENT TRIGGER, CREATE FUNCTION