]> begriffs open source - ai-pg/blob - full-docs/txt/event-trigger-interface.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / event-trigger-interface.txt
1
2 38.2. Writing Event Trigger Functions in C #
3
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.
11
12    Event trigger functions must use the “version 1” function manager
13    interface.
14
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
19    macro:
20 CALLED_AS_EVENT_TRIGGER(fcinfo)
21
22    which expands to:
23 ((fcinfo)->context != NULL && IsA((fcinfo)->context, EventTriggerData))
24
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.
29
30    struct EventTriggerData is defined in commands/event_trigger.h:
31 typedef struct EventTriggerData
32 {
33     NodeTag     type;
34     const char *event;      /* event name */
35     Node       *parsetree;  /* parse tree */
36     CommandTag  tag;        /* command tag */
37 } EventTriggerData;
38
39    where the members are defined as follows:
40
41    type
42           Always T_EventTriggerData.
43
44    event
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
48           events.
49
50    parsetree
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.
54
55    tag
56           The command tag associated with the event for which the event
57           trigger is run, for example "CREATE FUNCTION".
58
59    An event trigger function must return a NULL pointer (not an SQL null
60    value, that is, do not set isNull true).