2 38.2. Writing Event Trigger Functions in C #
4 This section describes the low-level details of the interface to an
5 event trigger function. This information is only needed when writing
6 event trigger functions in C. If you are using a higher-level language
7 then these details are handled for you. In most cases you should
8 consider using a procedural language before writing your event triggers
9 in C. The documentation of each procedural language explains how to
10 write an event trigger in that language.
12 Event trigger functions must use the “version 1” function manager
15 When a function is called by the event trigger manager, it is not
16 passed any normal arguments, but it is passed a “context” pointer
17 pointing to a EventTriggerData structure. C functions can check whether
18 they were called from the event trigger manager or not by executing the
20 CALLED_AS_EVENT_TRIGGER(fcinfo)
23 ((fcinfo)->context != NULL && IsA((fcinfo)->context, EventTriggerData))
25 If this returns true, then it is safe to cast fcinfo->context to type
26 EventTriggerData * and make use of the pointed-to EventTriggerData
27 structure. The function must not alter the EventTriggerData structure
28 or any of the data it points to.
30 struct EventTriggerData is defined in commands/event_trigger.h:
31 typedef struct EventTriggerData
34 const char *event; /* event name */
35 Node *parsetree; /* parse tree */
36 CommandTag tag; /* command tag */
39 where the members are defined as follows:
42 Always T_EventTriggerData.
45 Describes the event for which the function is called, one of
46 "login", "ddl_command_start", "ddl_command_end", "sql_drop",
47 "table_rewrite". See Section 38.1 for the meaning of these
51 A pointer to the parse tree of the command. Check the PostgreSQL
52 source code for details. The parse tree structure is subject to
53 change without notice.
56 The command tag associated with the event for which the event
57 trigger is run, for example "CREATE FUNCTION".
59 An event trigger function must return a NULL pointer (not an SQL null
60 value, that is, do not set isNull true).