Header And Logo

PostgreSQL
| The world's most advanced open source database.

pg_trigger.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * pg_trigger.h
00004  *    definition of the system "trigger" relation (pg_trigger)
00005  *    along with the relation's initial contents.
00006  *
00007  *
00008  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00009  * Portions Copyright (c) 1994, Regents of the University of California
00010  *
00011  * src/include/catalog/pg_trigger.h
00012  *
00013  * NOTES
00014  *    the genbki.pl script reads this file and generates .bki
00015  *    information from the DATA() statements.
00016  *
00017  *-------------------------------------------------------------------------
00018  */
00019 #ifndef PG_TRIGGER_H
00020 #define PG_TRIGGER_H
00021 
00022 #include "catalog/genbki.h"
00023 
00024 /* ----------------
00025  *      pg_trigger definition.  cpp turns this into
00026  *      typedef struct FormData_pg_trigger
00027  *
00028  * Note: when tgconstraint is nonzero, tgconstrrelid, tgconstrindid,
00029  * tgdeferrable, and tginitdeferred are largely redundant with the referenced
00030  * pg_constraint entry.  However, it is possible for a non-deferrable trigger
00031  * to be associated with a deferrable constraint.
00032  * ----------------
00033  */
00034 #define TriggerRelationId  2620
00035 
00036 CATALOG(pg_trigger,2620)
00037 {
00038     Oid         tgrelid;        /* relation trigger is attached to */
00039     NameData    tgname;         /* trigger's name */
00040     Oid         tgfoid;         /* OID of function to be called */
00041     int16       tgtype;         /* BEFORE/AFTER/INSTEAD, UPDATE/DELETE/INSERT,
00042                                  * ROW/STATEMENT; see below */
00043     char        tgenabled;      /* trigger's firing configuration WRT
00044                                  * session_replication_role */
00045     bool        tgisinternal;   /* trigger is system-generated */
00046     Oid         tgconstrrelid;  /* constraint's FROM table, if any */
00047     Oid         tgconstrindid;  /* constraint's supporting index, if any */
00048     Oid         tgconstraint;   /* associated pg_constraint entry, if any */
00049     bool        tgdeferrable;   /* constraint trigger is deferrable */
00050     bool        tginitdeferred; /* constraint trigger is deferred initially */
00051     int16       tgnargs;        /* # of extra arguments in tgargs */
00052 
00053     /*
00054      * Variable-length fields start here, but we allow direct access to
00055      * tgattr. Note: tgattr and tgargs must not be null.
00056      */
00057     int2vector  tgattr;         /* column numbers, if trigger is on columns */
00058 
00059 #ifdef CATALOG_VARLEN
00060     bytea       tgargs;         /* first\000second\000tgnargs\000 */
00061     pg_node_tree tgqual;        /* WHEN expression, or NULL if none */
00062 #endif
00063 } FormData_pg_trigger;
00064 
00065 /* ----------------
00066  *      Form_pg_trigger corresponds to a pointer to a tuple with
00067  *      the format of pg_trigger relation.
00068  * ----------------
00069  */
00070 typedef FormData_pg_trigger *Form_pg_trigger;
00071 
00072 /* ----------------
00073  *      compiler constants for pg_trigger
00074  * ----------------
00075  */
00076 #define Natts_pg_trigger                15
00077 #define Anum_pg_trigger_tgrelid         1
00078 #define Anum_pg_trigger_tgname          2
00079 #define Anum_pg_trigger_tgfoid          3
00080 #define Anum_pg_trigger_tgtype          4
00081 #define Anum_pg_trigger_tgenabled       5
00082 #define Anum_pg_trigger_tgisinternal    6
00083 #define Anum_pg_trigger_tgconstrrelid   7
00084 #define Anum_pg_trigger_tgconstrindid   8
00085 #define Anum_pg_trigger_tgconstraint    9
00086 #define Anum_pg_trigger_tgdeferrable    10
00087 #define Anum_pg_trigger_tginitdeferred  11
00088 #define Anum_pg_trigger_tgnargs         12
00089 #define Anum_pg_trigger_tgattr          13
00090 #define Anum_pg_trigger_tgargs          14
00091 #define Anum_pg_trigger_tgqual          15
00092 
00093 /* Bits within tgtype */
00094 #define TRIGGER_TYPE_ROW                (1 << 0)
00095 #define TRIGGER_TYPE_BEFORE             (1 << 1)
00096 #define TRIGGER_TYPE_INSERT             (1 << 2)
00097 #define TRIGGER_TYPE_DELETE             (1 << 3)
00098 #define TRIGGER_TYPE_UPDATE             (1 << 4)
00099 #define TRIGGER_TYPE_TRUNCATE           (1 << 5)
00100 #define TRIGGER_TYPE_INSTEAD            (1 << 6)
00101 
00102 #define TRIGGER_TYPE_LEVEL_MASK         (TRIGGER_TYPE_ROW)
00103 #define TRIGGER_TYPE_STATEMENT          0
00104 
00105 /* Note bits within TRIGGER_TYPE_TIMING_MASK aren't adjacent */
00106 #define TRIGGER_TYPE_TIMING_MASK \
00107     (TRIGGER_TYPE_BEFORE | TRIGGER_TYPE_INSTEAD)
00108 #define TRIGGER_TYPE_AFTER              0
00109 
00110 #define TRIGGER_TYPE_EVENT_MASK \
00111     (TRIGGER_TYPE_INSERT | TRIGGER_TYPE_DELETE | TRIGGER_TYPE_UPDATE | TRIGGER_TYPE_TRUNCATE)
00112 
00113 /* Macros for manipulating tgtype */
00114 #define TRIGGER_CLEAR_TYPE(type)        ((type) = 0)
00115 
00116 #define TRIGGER_SETT_ROW(type)          ((type) |= TRIGGER_TYPE_ROW)
00117 #define TRIGGER_SETT_STATEMENT(type)    ((type) |= TRIGGER_TYPE_STATEMENT)
00118 #define TRIGGER_SETT_BEFORE(type)       ((type) |= TRIGGER_TYPE_BEFORE)
00119 #define TRIGGER_SETT_AFTER(type)        ((type) |= TRIGGER_TYPE_AFTER)
00120 #define TRIGGER_SETT_INSTEAD(type)      ((type) |= TRIGGER_TYPE_INSTEAD)
00121 #define TRIGGER_SETT_INSERT(type)       ((type) |= TRIGGER_TYPE_INSERT)
00122 #define TRIGGER_SETT_DELETE(type)       ((type) |= TRIGGER_TYPE_DELETE)
00123 #define TRIGGER_SETT_UPDATE(type)       ((type) |= TRIGGER_TYPE_UPDATE)
00124 #define TRIGGER_SETT_TRUNCATE(type)     ((type) |= TRIGGER_TYPE_TRUNCATE)
00125 
00126 #define TRIGGER_FOR_ROW(type)           ((type) & TRIGGER_TYPE_ROW)
00127 #define TRIGGER_FOR_BEFORE(type)        (((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_BEFORE)
00128 #define TRIGGER_FOR_AFTER(type)         (((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_AFTER)
00129 #define TRIGGER_FOR_INSTEAD(type)       (((type) & TRIGGER_TYPE_TIMING_MASK) == TRIGGER_TYPE_INSTEAD)
00130 #define TRIGGER_FOR_INSERT(type)        ((type) & TRIGGER_TYPE_INSERT)
00131 #define TRIGGER_FOR_DELETE(type)        ((type) & TRIGGER_TYPE_DELETE)
00132 #define TRIGGER_FOR_UPDATE(type)        ((type) & TRIGGER_TYPE_UPDATE)
00133 #define TRIGGER_FOR_TRUNCATE(type)      ((type) & TRIGGER_TYPE_TRUNCATE)
00134 
00135 /*
00136  * Efficient macro for checking if tgtype matches a particular level
00137  * (TRIGGER_TYPE_ROW or TRIGGER_TYPE_STATEMENT), timing (TRIGGER_TYPE_BEFORE,
00138  * TRIGGER_TYPE_AFTER or TRIGGER_TYPE_INSTEAD), and event (TRIGGER_TYPE_INSERT,
00139  * TRIGGER_TYPE_DELETE, TRIGGER_TYPE_UPDATE, or TRIGGER_TYPE_TRUNCATE).  Note
00140  * that a tgtype can match more than one event, but only one level or timing.
00141  */
00142 #define TRIGGER_TYPE_MATCHES(type, level, timing, event) \
00143     (((type) & (TRIGGER_TYPE_LEVEL_MASK | TRIGGER_TYPE_TIMING_MASK | (event))) == ((level) | (timing) | (event)))
00144 
00145 #endif   /* PG_TRIGGER_H */