PostgreSQL Source Code  git master
pg_trigger.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_trigger.h
4  * definition of the "trigger" system catalog (pg_trigger)
5  *
6  *
7  * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/catalog/pg_trigger.h
11  *
12  * NOTES
13  * The Catalog.pm module reads this file and derives schema
14  * information.
15  *
16  *-------------------------------------------------------------------------
17  */
18 #ifndef PG_TRIGGER_H
19 #define PG_TRIGGER_H
20 
21 #include "catalog/genbki.h"
22 #include "catalog/pg_trigger_d.h"
23 
24 /* ----------------
25  * pg_trigger definition. cpp turns this into
26  * typedef struct FormData_pg_trigger
27  *
28  * Note: when tgconstraint is nonzero, tgconstrrelid, tgconstrindid,
29  * tgdeferrable, and tginitdeferred are largely redundant with the referenced
30  * pg_constraint entry. However, it is possible for a non-deferrable trigger
31  * to be associated with a deferrable constraint.
32  * ----------------
33  */
34 CATALOG(pg_trigger,2620,TriggerRelationId)
35 {
36  Oid oid; /* oid */
37  Oid tgrelid; /* relation trigger is attached to */
38  Oid tgparentid; /* OID of parent trigger, if any */
39  NameData tgname; /* trigger's name */
40  Oid tgfoid; /* OID of function to be called */
41  int16 tgtype; /* BEFORE/AFTER/INSTEAD, UPDATE/DELETE/INSERT,
42  * ROW/STATEMENT; see below */
43  char tgenabled; /* trigger's firing configuration WRT
44  * session_replication_role */
45  bool tgisinternal; /* trigger is system-generated */
46  Oid tgconstrrelid; /* constraint's FROM table, if any */
47  Oid tgconstrindid; /* constraint's supporting index, if any */
48  Oid tgconstraint; /* associated pg_constraint entry, if any */
49  bool tgdeferrable; /* constraint trigger is deferrable */
50  bool tginitdeferred; /* constraint trigger is deferred initially */
51  int16 tgnargs; /* # of extra arguments in tgargs */
52 
53  /*
54  * Variable-length fields start here, but we allow direct access to
55  * tgattr. Note: tgattr and tgargs must not be null.
56  */
57  int2vector tgattr BKI_FORCE_NOT_NULL; /* column numbers, if trigger is
58  * on columns */
59 
60 #ifdef CATALOG_VARLEN
61  bytea tgargs BKI_FORCE_NOT_NULL; /* first\000second\000tgnargs\000 */
62  pg_node_tree tgqual; /* WHEN expression, or NULL if none */
63  NameData tgoldtable; /* old transition table, or NULL if none */
64  NameData tgnewtable; /* new transition table, or NULL if none */
65 #endif
67 
68 /* ----------------
69  * Form_pg_trigger corresponds to a pointer to a tuple with
70  * the format of pg_trigger relation.
71  * ----------------
72  */
74 
75 #ifdef EXPOSE_TO_CLIENT_CODE
76 
77 /* Bits within tgtype */
78 #define TRIGGER_TYPE_ROW (1 << 0)
79 #define TRIGGER_TYPE_BEFORE (1 << 1)
80 #define TRIGGER_TYPE_INSERT (1 << 2)
81 #define TRIGGER_TYPE_DELETE (1 << 3)
82 #define TRIGGER_TYPE_UPDATE (1 << 4)
83 #define TRIGGER_TYPE_TRUNCATE (1 << 5)
84 #define TRIGGER_TYPE_INSTEAD (1 << 6)
85 
86 #define TRIGGER_TYPE_LEVEL_MASK (TRIGGER_TYPE_ROW)
87 #define TRIGGER_TYPE_STATEMENT 0
88 
89 /* Note bits within TRIGGER_TYPE_TIMING_MASK aren't adjacent */
90 #define TRIGGER_TYPE_TIMING_MASK \
91  (TRIGGER_TYPE_BEFORE | TRIGGER_TYPE_INSTEAD)
92 #define TRIGGER_TYPE_AFTER 0
93 
94 #define TRIGGER_TYPE_EVENT_MASK \
95  (TRIGGER_TYPE_INSERT | TRIGGER_TYPE_DELETE | TRIGGER_TYPE_UPDATE | TRIGGER_TYPE_TRUNCATE)
96 
97 /* Macros for manipulating tgtype */
98 #define TRIGGER_CLEAR_TYPE(type) ((type) = 0)
99 
100 #define TRIGGER_SETT_ROW(type) ((type) |= TRIGGER_TYPE_ROW)
101 #define TRIGGER_SETT_STATEMENT(type) ((type) |= TRIGGER_TYPE_STATEMENT)
102 #define TRIGGER_SETT_BEFORE(type) ((type) |= TRIGGER_TYPE_BEFORE)
103 #define TRIGGER_SETT_AFTER(type) ((type) |= TRIGGER_TYPE_AFTER)
104 #define TRIGGER_SETT_INSTEAD(type) ((type) |= TRIGGER_TYPE_INSTEAD)
105 #define TRIGGER_SETT_INSERT(type) ((type) |= TRIGGER_TYPE_INSERT)
106 #define TRIGGER_SETT_DELETE(type) ((type) |= TRIGGER_TYPE_DELETE)
107 #define TRIGGER_SETT_UPDATE(type) ((type) |= TRIGGER_TYPE_UPDATE)
108 #define TRIGGER_SETT_TRUNCATE(type) ((type) |= TRIGGER_TYPE_TRUNCATE)
109 
110 #define TRIGGER_FOR_ROW(type) ((type) & TRIGGER_TYPE_ROW)
111 #define TRIGGER_FOR_BEFORE(type) (((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_BEFORE)
112 #define TRIGGER_FOR_AFTER(type) (((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_AFTER)
113 #define TRIGGER_FOR_INSTEAD(type) (((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_INSTEAD)
114 #define TRIGGER_FOR_INSERT(type) ((type) & TRIGGER_TYPE_INSERT)
115 #define TRIGGER_FOR_DELETE(type) ((type) & TRIGGER_TYPE_DELETE)
116 #define TRIGGER_FOR_UPDATE(type) ((type) & TRIGGER_TYPE_UPDATE)
117 #define TRIGGER_FOR_TRUNCATE(type) ((type) & TRIGGER_TYPE_TRUNCATE)
118 
119 /*
120  * Efficient macro for checking if tgtype matches a particular level
121  * (TRIGGER_TYPE_ROW or TRIGGER_TYPE_STATEMENT), timing (TRIGGER_TYPE_BEFORE,
122  * TRIGGER_TYPE_AFTER or TRIGGER_TYPE_INSTEAD), and event (TRIGGER_TYPE_INSERT,
123  * TRIGGER_TYPE_DELETE, TRIGGER_TYPE_UPDATE, or TRIGGER_TYPE_TRUNCATE). Note
124  * that a tgtype can match more than one event, but only one level or timing.
125  */
126 #define TRIGGER_TYPE_MATCHES(type, level, timing, event) \
127  (((type) & (TRIGGER_TYPE_LEVEL_MASK | TRIGGER_TYPE_TIMING_MASK | (event))) == ((level) | (timing) | (event)))
128 
129 /*
130  * Macro to determine whether tgnewtable or tgoldtable has been specified for
131  * a trigger.
132  */
133 #define TRIGGER_USES_TRANSITION_TABLE(namepointer) \
134  ((namepointer) != (char *) NULL)
135 
136 #endif /* EXPOSE_TO_CLIENT_CODE */
137 
138 #endif /* PG_TRIGGER_H */
signed short int16
Definition: c.h:361
FormData_pg_trigger
Definition: pg_trigger.h:66
unsigned int Oid
Definition: postgres_ext.h:31
#define BKI_FORCE_NOT_NULL
Definition: genbki.h:33
Definition: c.h:616
CATALOG(pg_trigger, 2620, TriggerRelationId)
Definition: pg_trigger.h:34
Definition: c.h:590
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:73
Definition: c.h:562