1
/*-------------------------------------------------------------------------
4
* definition of the system "trigger" relation (pg_trigger)
5
* along with the relation's initial contents.
8
* Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
9
* Portions Copyright (c) 1994, Regents of the University of California
11
* src/include/catalog/pg_trigger.h
14
* the genbki.pl script reads this file and generates .bki
15
* information from the DATA() statements.
17
*-------------------------------------------------------------------------
22
#include "catalog/genbki.h"
25
* pg_trigger definition. cpp turns this into
26
* typedef struct FormData_pg_trigger
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.
34
#define TriggerRelationId 2620
36
CATALOG(pg_trigger,2620)
38
Oid tgrelid; /* relation trigger is attached to */
39
NameData tgname; /* trigger's name */
40
Oid tgfoid; /* OID of function to be called */
41
int2 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
int2 tgnargs; /* # of extra arguments in tgargs */
53
/* VARIABLE LENGTH FIELDS (note: tgattr and tgargs must not be null) */
54
int2vector tgattr; /* column numbers, if trigger is on columns */
55
bytea tgargs; /* first\000second\000tgnargs\000 */
56
pg_node_tree tgqual; /* WHEN expression, or NULL if none */
57
} FormData_pg_trigger;
60
* Form_pg_trigger corresponds to a pointer to a tuple with
61
* the format of pg_trigger relation.
64
typedef FormData_pg_trigger *Form_pg_trigger;
67
* compiler constants for pg_trigger
70
#define Natts_pg_trigger 15
71
#define Anum_pg_trigger_tgrelid 1
72
#define Anum_pg_trigger_tgname 2
73
#define Anum_pg_trigger_tgfoid 3
74
#define Anum_pg_trigger_tgtype 4
75
#define Anum_pg_trigger_tgenabled 5
76
#define Anum_pg_trigger_tgisinternal 6
77
#define Anum_pg_trigger_tgconstrrelid 7
78
#define Anum_pg_trigger_tgconstrindid 8
79
#define Anum_pg_trigger_tgconstraint 9
80
#define Anum_pg_trigger_tgdeferrable 10
81
#define Anum_pg_trigger_tginitdeferred 11
82
#define Anum_pg_trigger_tgnargs 12
83
#define Anum_pg_trigger_tgattr 13
84
#define Anum_pg_trigger_tgargs 14
85
#define Anum_pg_trigger_tgqual 15
87
/* Bits within tgtype */
88
#define TRIGGER_TYPE_ROW (1 << 0)
89
#define TRIGGER_TYPE_BEFORE (1 << 1)
90
#define TRIGGER_TYPE_INSERT (1 << 2)
91
#define TRIGGER_TYPE_DELETE (1 << 3)
92
#define TRIGGER_TYPE_UPDATE (1 << 4)
93
#define TRIGGER_TYPE_TRUNCATE (1 << 5)
94
#define TRIGGER_TYPE_INSTEAD (1 << 6)
96
#define TRIGGER_TYPE_LEVEL_MASK (TRIGGER_TYPE_ROW)
97
#define TRIGGER_TYPE_STATEMENT 0
99
/* Note bits within TRIGGER_TYPE_TIMING_MASK aren't adjacent */
100
#define TRIGGER_TYPE_TIMING_MASK \
101
(TRIGGER_TYPE_BEFORE | TRIGGER_TYPE_INSTEAD)
102
#define TRIGGER_TYPE_AFTER 0
104
#define TRIGGER_TYPE_EVENT_MASK \
105
(TRIGGER_TYPE_INSERT | TRIGGER_TYPE_DELETE | TRIGGER_TYPE_UPDATE | TRIGGER_TYPE_TRUNCATE)
107
/* Macros for manipulating tgtype */
108
#define TRIGGER_CLEAR_TYPE(type) ((type) = 0)
110
#define TRIGGER_SETT_ROW(type) ((type) |= TRIGGER_TYPE_ROW)
111
#define TRIGGER_SETT_STATEMENT(type) ((type) |= TRIGGER_TYPE_STATEMENT)
112
#define TRIGGER_SETT_BEFORE(type) ((type) |= TRIGGER_TYPE_BEFORE)
113
#define TRIGGER_SETT_AFTER(type) ((type) |= TRIGGER_TYPE_AFTER)
114
#define TRIGGER_SETT_INSTEAD(type) ((type) |= TRIGGER_TYPE_INSTEAD)
115
#define TRIGGER_SETT_INSERT(type) ((type) |= TRIGGER_TYPE_INSERT)
116
#define TRIGGER_SETT_DELETE(type) ((type) |= TRIGGER_TYPE_DELETE)
117
#define TRIGGER_SETT_UPDATE(type) ((type) |= TRIGGER_TYPE_UPDATE)
118
#define TRIGGER_SETT_TRUNCATE(type) ((type) |= TRIGGER_TYPE_TRUNCATE)
120
#define TRIGGER_FOR_ROW(type) ((type) & TRIGGER_TYPE_ROW)
121
#define TRIGGER_FOR_BEFORE(type) (((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_BEFORE)
122
#define TRIGGER_FOR_AFTER(type) (((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_AFTER)
123
#define TRIGGER_FOR_INSTEAD(type) (((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_INSTEAD)
124
#define TRIGGER_FOR_INSERT(type) ((type) & TRIGGER_TYPE_INSERT)
125
#define TRIGGER_FOR_DELETE(type) ((type) & TRIGGER_TYPE_DELETE)
126
#define TRIGGER_FOR_UPDATE(type) ((type) & TRIGGER_TYPE_UPDATE)
127
#define TRIGGER_FOR_TRUNCATE(type) ((type) & TRIGGER_TYPE_TRUNCATE)
130
* Efficient macro for checking if tgtype matches a particular level
131
* (TRIGGER_TYPE_ROW or TRIGGER_TYPE_STATEMENT), timing (TRIGGER_TYPE_BEFORE,
132
* TRIGGER_TYPE_AFTER or TRIGGER_TYPE_INSTEAD), and event (TRIGGER_TYPE_INSERT,
133
* TRIGGER_TYPE_DELETE, TRIGGER_TYPE_UPDATE, or TRIGGER_TYPE_TRUNCATE). Note
134
* that a tgtype can match more than one event, but only one level or timing.
136
#define TRIGGER_TYPE_MATCHES(type, level, timing, event) \
137
(((type) & (TRIGGER_TYPE_LEVEL_MASK | TRIGGER_TYPE_TIMING_MASK | (event))) == ((level) | (timing) | (event)))
139
#endif /* PG_TRIGGER_H */