PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_trigger.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_trigger.h
4  * definition of the system "trigger" relation (pg_trigger)
5  * along with the relation's initial contents.
6  *
7  *
8  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
9  * Portions Copyright (c) 1994, Regents of the University of California
10  *
11  * src/include/catalog/pg_trigger.h
12  *
13  * NOTES
14  * the genbki.pl script reads this file and generates .bki
15  * information from the DATA() statements.
16  *
17  *-------------------------------------------------------------------------
18  */
19 #ifndef PG_TRIGGER_H
20 #define PG_TRIGGER_H
21 
22 #include "catalog/genbki.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 #define TriggerRelationId 2620
35 
36 CATALOG(pg_trigger,2620)
37 {
38  Oid tgrelid; /* relation trigger is attached to */
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; /* column numbers, if trigger is on columns */
58 
59 #ifdef CATALOG_VARLEN
60  bytea tgargs BKI_FORCE_NOT_NULL; /* first\000second\000tgnargs\000 */
61  pg_node_tree tgqual; /* WHEN expression, or NULL if none */
62  NameData tgoldtable; /* old transition table, or NULL if none */
63  NameData tgnewtable; /* new transition table, or NULL if none */
64 #endif
66 
67 /* ----------------
68  * Form_pg_trigger corresponds to a pointer to a tuple with
69  * the format of pg_trigger relation.
70  * ----------------
71  */
73 
74 /* ----------------
75  * compiler constants for pg_trigger
76  * ----------------
77  */
78 #define Natts_pg_trigger 17
79 #define Anum_pg_trigger_tgrelid 1
80 #define Anum_pg_trigger_tgname 2
81 #define Anum_pg_trigger_tgfoid 3
82 #define Anum_pg_trigger_tgtype 4
83 #define Anum_pg_trigger_tgenabled 5
84 #define Anum_pg_trigger_tgisinternal 6
85 #define Anum_pg_trigger_tgconstrrelid 7
86 #define Anum_pg_trigger_tgconstrindid 8
87 #define Anum_pg_trigger_tgconstraint 9
88 #define Anum_pg_trigger_tgdeferrable 10
89 #define Anum_pg_trigger_tginitdeferred 11
90 #define Anum_pg_trigger_tgnargs 12
91 #define Anum_pg_trigger_tgattr 13
92 #define Anum_pg_trigger_tgargs 14
93 #define Anum_pg_trigger_tgqual 15
94 #define Anum_pg_trigger_tgoldtable 16
95 #define Anum_pg_trigger_tgnewtable 17
96 
97 /* Bits within tgtype */
98 #define TRIGGER_TYPE_ROW (1 << 0)
99 #define TRIGGER_TYPE_BEFORE (1 << 1)
100 #define TRIGGER_TYPE_INSERT (1 << 2)
101 #define TRIGGER_TYPE_DELETE (1 << 3)
102 #define TRIGGER_TYPE_UPDATE (1 << 4)
103 #define TRIGGER_TYPE_TRUNCATE (1 << 5)
104 #define TRIGGER_TYPE_INSTEAD (1 << 6)
105 
106 #define TRIGGER_TYPE_LEVEL_MASK (TRIGGER_TYPE_ROW)
107 #define TRIGGER_TYPE_STATEMENT 0
108 
109 /* Note bits within TRIGGER_TYPE_TIMING_MASK aren't adjacent */
110 #define TRIGGER_TYPE_TIMING_MASK \
111  (TRIGGER_TYPE_BEFORE | TRIGGER_TYPE_INSTEAD)
112 #define TRIGGER_TYPE_AFTER 0
113 
114 #define TRIGGER_TYPE_EVENT_MASK \
115  (TRIGGER_TYPE_INSERT | TRIGGER_TYPE_DELETE | TRIGGER_TYPE_UPDATE | TRIGGER_TYPE_TRUNCATE)
116 
117 /* Macros for manipulating tgtype */
118 #define TRIGGER_CLEAR_TYPE(type) ((type) = 0)
119 
120 #define TRIGGER_SETT_ROW(type) ((type) |= TRIGGER_TYPE_ROW)
121 #define TRIGGER_SETT_STATEMENT(type) ((type) |= TRIGGER_TYPE_STATEMENT)
122 #define TRIGGER_SETT_BEFORE(type) ((type) |= TRIGGER_TYPE_BEFORE)
123 #define TRIGGER_SETT_AFTER(type) ((type) |= TRIGGER_TYPE_AFTER)
124 #define TRIGGER_SETT_INSTEAD(type) ((type) |= TRIGGER_TYPE_INSTEAD)
125 #define TRIGGER_SETT_INSERT(type) ((type) |= TRIGGER_TYPE_INSERT)
126 #define TRIGGER_SETT_DELETE(type) ((type) |= TRIGGER_TYPE_DELETE)
127 #define TRIGGER_SETT_UPDATE(type) ((type) |= TRIGGER_TYPE_UPDATE)
128 #define TRIGGER_SETT_TRUNCATE(type) ((type) |= TRIGGER_TYPE_TRUNCATE)
129 
130 #define TRIGGER_FOR_ROW(type) ((type) & TRIGGER_TYPE_ROW)
131 #define TRIGGER_FOR_BEFORE(type) (((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_BEFORE)
132 #define TRIGGER_FOR_AFTER(type) (((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_AFTER)
133 #define TRIGGER_FOR_INSTEAD(type) (((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_INSTEAD)
134 #define TRIGGER_FOR_INSERT(type) ((type) & TRIGGER_TYPE_INSERT)
135 #define TRIGGER_FOR_DELETE(type) ((type) & TRIGGER_TYPE_DELETE)
136 #define TRIGGER_FOR_UPDATE(type) ((type) & TRIGGER_TYPE_UPDATE)
137 #define TRIGGER_FOR_TRUNCATE(type) ((type) & TRIGGER_TYPE_TRUNCATE)
138 
139 /*
140  * Efficient macro for checking if tgtype matches a particular level
141  * (TRIGGER_TYPE_ROW or TRIGGER_TYPE_STATEMENT), timing (TRIGGER_TYPE_BEFORE,
142  * TRIGGER_TYPE_AFTER or TRIGGER_TYPE_INSTEAD), and event (TRIGGER_TYPE_INSERT,
143  * TRIGGER_TYPE_DELETE, TRIGGER_TYPE_UPDATE, or TRIGGER_TYPE_TRUNCATE). Note
144  * that a tgtype can match more than one event, but only one level or timing.
145  */
146 #define TRIGGER_TYPE_MATCHES(type, level, timing, event) \
147  (((type) & (TRIGGER_TYPE_LEVEL_MASK | TRIGGER_TYPE_TIMING_MASK | (event))) == ((level) | (timing) | (event)))
148 
149 /*
150  * Macro to determine whether tgnewtable or tgoldtable has been specified for
151  * a trigger.
152  */
153 #define TRIGGER_USES_TRANSITION_TABLE(namepointer) \
154  ((namepointer) != (char *) NULL)
155 
156 #endif /* PG_TRIGGER_H */
signed short int16
Definition: c.h:255
FormData_pg_trigger
Definition: pg_trigger.h:65
unsigned int Oid
Definition: postgres_ext.h:31
#define BKI_FORCE_NOT_NULL
Definition: genbki.h:32
CATALOG(pg_trigger, 2620)
Definition: pg_trigger.h:36
Definition: c.h:493
Definition: c.h:467
FormData_pg_trigger * Form_pg_trigger
Definition: pg_trigger.h:72
Definition: c.h:439