]> begriffs open source - ai-pg/blob - full-docs/txt/sql-createeventtrigger.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / sql-createeventtrigger.txt
1
2 CREATE EVENT TRIGGER
3
4    CREATE EVENT TRIGGER — define a new event trigger
5
6 Synopsis
7
8 CREATE EVENT TRIGGER name
9     ON event
10     [ WHEN filter_variable IN (filter_value [, ... ]) [ AND ... ] ]
11     EXECUTE { FUNCTION | PROCEDURE } function_name()
12
13 Description
14
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.
20
21 Parameters
22
23    name
24           The name to give the new trigger. This name must be unique
25           within the database.
26
27    event
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.
30
31    filter_variable
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.
36
37    filter_value
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').
41
42    function_name
43           A user-supplied function that is declared as taking no argument
44           and returning type event_trigger.
45
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.
50
51 Notes
52
53    Only superusers can create event triggers.
54
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.
60
61 Examples
62
63    Forbid the execution of any DDL command:
64 CREATE OR REPLACE FUNCTION abort_any_command()
65   RETURNS event_trigger
66  LANGUAGE plpgsql
67   AS $$
68 BEGIN
69   RAISE EXCEPTION 'command % is disabled', tg_tag;
70 END;
71 $$;
72
73 CREATE EVENT TRIGGER abort_ddl ON ddl_command_start
74    EXECUTE FUNCTION abort_any_command();
75
76 Compatibility
77
78    There is no CREATE EVENT TRIGGER statement in the SQL standard.
79
80 See Also
81
82    ALTER EVENT TRIGGER, DROP EVENT TRIGGER, CREATE FUNCTION