PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pg_constraint.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * pg_constraint.h
4  * definition of the system "constraint" relation (pg_constraint)
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_constraint.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_CONSTRAINT_H
20 #define PG_CONSTRAINT_H
21 
22 #include "catalog/genbki.h"
23 
24 /* ----------------
25  * pg_constraint definition. cpp turns this into
26  * typedef struct FormData_pg_constraint
27  * ----------------
28  */
29 #define ConstraintRelationId 2606
30 
31 CATALOG(pg_constraint,2606)
32 {
33  /*
34  * conname + connamespace is deliberately not unique; we allow, for
35  * example, the same name to be used for constraints of different
36  * relations. This is partly for backwards compatibility with past
37  * Postgres practice, and partly because we don't want to have to obtain a
38  * global lock to generate a globally unique name for a nameless
39  * constraint. We associate a namespace with constraint names only for
40  * SQL-spec compatibility.
41  */
42  NameData conname; /* name of this constraint */
43  Oid connamespace; /* OID of namespace containing constraint */
44  char contype; /* constraint type; see codes below */
45  bool condeferrable; /* deferrable constraint? */
46  bool condeferred; /* deferred by default? */
47  bool convalidated; /* constraint has been validated? */
48 
49  /*
50  * conrelid and conkey are only meaningful if the constraint applies to a
51  * specific relation (this excludes domain constraints and assertions).
52  * Otherwise conrelid is 0 and conkey is NULL.
53  */
54  Oid conrelid; /* relation this constraint constrains */
55 
56  /*
57  * contypid links to the pg_type row for a domain if this is a domain
58  * constraint. Otherwise it's 0.
59  *
60  * For SQL-style global ASSERTIONs, both conrelid and contypid would be
61  * zero. This is not presently supported, however.
62  */
63  Oid contypid; /* domain this constraint constrains */
64 
65  /*
66  * conindid links to the index supporting the constraint, if any;
67  * otherwise it's 0. This is used for unique, primary-key, and exclusion
68  * constraints, and less obviously for foreign-key constraints (where the
69  * index is a unique index on the referenced relation's referenced
70  * columns). Notice that the index is on conrelid in the first case but
71  * confrelid in the second.
72  */
73  Oid conindid; /* index supporting this constraint */
74 
75  /*
76  * These fields, plus confkey, are only meaningful for a foreign-key
77  * constraint. Otherwise confrelid is 0 and the char fields are spaces.
78  */
79  Oid confrelid; /* relation referenced by foreign key */
80  char confupdtype; /* foreign key's ON UPDATE action */
81  char confdeltype; /* foreign key's ON DELETE action */
82  char confmatchtype; /* foreign key's match type */
83 
84  /* Has a local definition (hence, do not drop when coninhcount is 0) */
85  bool conislocal;
86 
87  /* Number of times inherited from direct parent relation(s) */
88  int32 coninhcount;
89 
90  /* Has a local definition and cannot be inherited */
91  bool connoinherit;
92 
93 #ifdef CATALOG_VARLEN /* variable-length fields start here */
94 
95  /*
96  * Columns of conrelid that the constraint applies to, if known (this is
97  * NULL for trigger constraints)
98  */
99  int16 conkey[1];
100 
101  /*
102  * If a foreign key, the referenced columns of confrelid
103  */
104  int16 confkey[1];
105 
106  /*
107  * If a foreign key, the OIDs of the PK = FK equality operators for each
108  * column of the constraint
109  */
110  Oid conpfeqop[1];
111 
112  /*
113  * If a foreign key, the OIDs of the PK = PK equality operators for each
114  * column of the constraint (i.e., equality for the referenced columns)
115  */
116  Oid conppeqop[1];
117 
118  /*
119  * If a foreign key, the OIDs of the FK = FK equality operators for each
120  * column of the constraint (i.e., equality for the referencing columns)
121  */
122  Oid conffeqop[1];
123 
124  /*
125  * If an exclusion constraint, the OIDs of the exclusion operators for
126  * each column of the constraint
127  */
128  Oid conexclop[1];
129 
130  /*
131  * If a check constraint, nodeToString representation of expression
132  */
133  pg_node_tree conbin;
134 
135  /*
136  * If a check constraint, source-text representation of expression
137  */
138  text consrc;
139 #endif
141 
142 /* ----------------
143  * Form_pg_constraint corresponds to a pointer to a tuple with
144  * the format of pg_constraint relation.
145  * ----------------
146  */
148 
149 /* ----------------
150  * compiler constants for pg_constraint
151  * ----------------
152  */
153 #define Natts_pg_constraint 24
154 #define Anum_pg_constraint_conname 1
155 #define Anum_pg_constraint_connamespace 2
156 #define Anum_pg_constraint_contype 3
157 #define Anum_pg_constraint_condeferrable 4
158 #define Anum_pg_constraint_condeferred 5
159 #define Anum_pg_constraint_convalidated 6
160 #define Anum_pg_constraint_conrelid 7
161 #define Anum_pg_constraint_contypid 8
162 #define Anum_pg_constraint_conindid 9
163 #define Anum_pg_constraint_confrelid 10
164 #define Anum_pg_constraint_confupdtype 11
165 #define Anum_pg_constraint_confdeltype 12
166 #define Anum_pg_constraint_confmatchtype 13
167 #define Anum_pg_constraint_conislocal 14
168 #define Anum_pg_constraint_coninhcount 15
169 #define Anum_pg_constraint_connoinherit 16
170 #define Anum_pg_constraint_conkey 17
171 #define Anum_pg_constraint_confkey 18
172 #define Anum_pg_constraint_conpfeqop 19
173 #define Anum_pg_constraint_conppeqop 20
174 #define Anum_pg_constraint_conffeqop 21
175 #define Anum_pg_constraint_conexclop 22
176 #define Anum_pg_constraint_conbin 23
177 #define Anum_pg_constraint_consrc 24
178 
179 /* ----------------
180  * initial contents of pg_constraint
181  * ----------------
182  */
183 
184 /* nothing, at present */
185 
186 
187 /* Valid values for contype */
188 #define CONSTRAINT_CHECK 'c'
189 #define CONSTRAINT_FOREIGN 'f'
190 #define CONSTRAINT_PRIMARY 'p'
191 #define CONSTRAINT_UNIQUE 'u'
192 #define CONSTRAINT_TRIGGER 't'
193 #define CONSTRAINT_EXCLUSION 'x'
194 
195 /*
196  * Valid values for confupdtype and confdeltype are the FKCONSTR_ACTION_xxx
197  * constants defined in parsenodes.h. Valid values for confmatchtype are
198  * the FKCONSTR_MATCH_xxx constants defined in parsenodes.h.
199  */
200 
201 #endif /* PG_CONSTRAINT_H */
signed short int16
Definition: c.h:255
FormData_pg_constraint
unsigned int Oid
Definition: postgres_ext.h:31
signed int int32
Definition: c.h:256
CATALOG(pg_constraint, 2606)
Definition: pg_constraint.h:31
Definition: c.h:493
FormData_pg_constraint * Form_pg_constraint
Definition: c.h:439