Fix obsolete comment regarding FSM truncation.
[PostgreSQL.git] / src / include / catalog / pg_constraint.h
blobd5a7d4842eaafdf9367c9351bcceb2d56468581a
1 /*-------------------------------------------------------------------------
3 * pg_constraint.h
4 * definition of the system "constraint" relation (pg_constraint)
5 * along with the relation's initial contents.
8 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
11 * $PostgreSQL$
13 * NOTES
14 * the genbki.sh script reads this file and generates .bki
15 * information from the DATA() statements.
17 *-------------------------------------------------------------------------
19 #ifndef PG_CONSTRAINT_H
20 #define PG_CONSTRAINT_H
22 #include "catalog/genbki.h"
23 #include "nodes/pg_list.h"
25 /* ----------------
26 * pg_constraint definition. cpp turns this into
27 * typedef struct FormData_pg_constraint
28 * ----------------
30 #define ConstraintRelationId 2606
32 CATALOG(pg_constraint,2606)
35 * conname + connamespace is deliberately not unique; we allow, for
36 * example, the same name to be used for constraints of different
37 * relations. This is partly for backwards compatibility with past
38 * Postgres practice, and partly because we don't want to have to obtain a
39 * global lock to generate a globally unique name for a nameless
40 * constraint. We associate a namespace with constraint names only for
41 * SQL92 compatibility.
43 NameData conname; /* name of this constraint */
44 Oid connamespace; /* OID of namespace containing constraint */
45 char contype; /* constraint type; see codes below */
46 bool condeferrable; /* deferrable constraint? */
47 bool condeferred; /* deferred by default? */
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.
54 Oid conrelid; /* relation this constraint constrains */
57 * contypid links to the pg_type row for a domain if this is a domain
58 * constraint. Otherwise it's 0.
60 * For SQL-style global ASSERTIONs, both conrelid and contypid would be
61 * zero. This is not presently supported, however.
63 Oid contypid; /* domain this constraint constrains */
66 * These fields, plus confkey, are only meaningful for a foreign-key
67 * constraint. Otherwise confrelid is 0 and the char fields are spaces.
69 Oid confrelid; /* relation referenced by foreign key */
70 char confupdtype; /* foreign key's ON UPDATE action */
71 char confdeltype; /* foreign key's ON DELETE action */
72 char confmatchtype; /* foreign key's match type */
74 /* Has a local definition (hence, do not drop when coninhcount is 0) */
75 bool conislocal;
77 /* Number of times inherited from direct parent relation(s) */
78 int4 coninhcount;
81 * VARIABLE LENGTH FIELDS start here. These fields may be NULL, too.
85 * Columns of conrelid that the constraint applies to
87 int2 conkey[1];
90 * If a foreign key, the referenced columns of confrelid
92 int2 confkey[1];
95 * If a foreign key, the OIDs of the PK = FK equality operators for each
96 * column of the constraint
98 Oid conpfeqop[1];
101 * If a foreign key, the OIDs of the PK = PK equality operators for each
102 * column of the constraint (i.e., equality for the referenced columns)
104 Oid conppeqop[1];
107 * If a foreign key, the OIDs of the FK = FK equality operators for each
108 * column of the constraint (i.e., equality for the referencing columns)
110 Oid conffeqop[1];
113 * If a check constraint, nodeToString representation of expression
115 text conbin;
118 * If a check constraint, source-text representation of expression
120 text consrc;
121 } FormData_pg_constraint;
123 /* ----------------
124 * Form_pg_constraint corresponds to a pointer to a tuple with
125 * the format of pg_constraint relation.
126 * ----------------
128 typedef FormData_pg_constraint *Form_pg_constraint;
130 /* ----------------
131 * compiler constants for pg_constraint
132 * ----------------
134 #define Natts_pg_constraint 20
135 #define Anum_pg_constraint_conname 1
136 #define Anum_pg_constraint_connamespace 2
137 #define Anum_pg_constraint_contype 3
138 #define Anum_pg_constraint_condeferrable 4
139 #define Anum_pg_constraint_condeferred 5
140 #define Anum_pg_constraint_conrelid 6
141 #define Anum_pg_constraint_contypid 7
142 #define Anum_pg_constraint_confrelid 8
143 #define Anum_pg_constraint_confupdtype 9
144 #define Anum_pg_constraint_confdeltype 10
145 #define Anum_pg_constraint_confmatchtype 11
146 #define Anum_pg_constraint_conislocal 12
147 #define Anum_pg_constraint_coninhcount 13
148 #define Anum_pg_constraint_conkey 14
149 #define Anum_pg_constraint_confkey 15
150 #define Anum_pg_constraint_conpfeqop 16
151 #define Anum_pg_constraint_conppeqop 17
152 #define Anum_pg_constraint_conffeqop 18
153 #define Anum_pg_constraint_conbin 19
154 #define Anum_pg_constraint_consrc 20
157 /* Valid values for contype */
158 #define CONSTRAINT_CHECK 'c'
159 #define CONSTRAINT_FOREIGN 'f'
160 #define CONSTRAINT_PRIMARY 'p'
161 #define CONSTRAINT_UNIQUE 'u'
164 * Valid values for confupdtype and confdeltype are the FKCONSTR_ACTION_xxx
165 * constants defined in parsenodes.h. Valid values for confmatchtype are
166 * the FKCONSTR_MATCH_xxx constants defined in parsenodes.h.
170 * Identify constraint type for lookup purposes
172 typedef enum ConstraintCategory
174 CONSTRAINT_RELATION,
175 CONSTRAINT_DOMAIN,
176 CONSTRAINT_ASSERTION /* for future expansion */
177 } ConstraintCategory;
180 * prototypes for functions in pg_constraint.c
182 extern Oid CreateConstraintEntry(const char *constraintName,
183 Oid constraintNamespace,
184 char constraintType,
185 bool isDeferrable,
186 bool isDeferred,
187 Oid relId,
188 const int16 *constraintKey,
189 int constraintNKeys,
190 Oid domainId,
191 Oid foreignRelId,
192 const int16 *foreignKey,
193 const Oid *pfEqOp,
194 const Oid *ppEqOp,
195 const Oid *ffEqOp,
196 int foreignNKeys,
197 char foreignUpdateType,
198 char foreignDeleteType,
199 char foreignMatchType,
200 Oid indexRelId,
201 Node *conExpr,
202 const char *conBin,
203 const char *conSrc,
204 bool conIsLocal,
205 int conInhCount);
207 extern void RemoveConstraintById(Oid conId);
208 extern void RenameConstraintById(Oid conId, const char *newname);
210 extern bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId,
211 Oid objNamespace, const char *conname);
212 extern char *ChooseConstraintName(const char *name1, const char *name2,
213 const char *label, Oid namespace,
214 List *others);
216 extern void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId,
217 Oid newNspId, bool isType);
219 #endif /* PG_CONSTRAINT_H */