1
/*-------------------------------------------------------------------------
4
* definition of the system "constraint" relation (pg_constraint)
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_constraint.h
14
* the genbki.pl 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"
26
* pg_constraint definition. cpp turns this into
27
* typedef struct FormData_pg_constraint
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
* SQL-spec 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? */
48
bool convalidated; /* constraint has been validated? */
51
* conrelid and conkey are only meaningful if the constraint applies to a
52
* specific relation (this excludes domain constraints and assertions).
53
* Otherwise conrelid is 0 and conkey is NULL.
55
Oid conrelid; /* relation this constraint constrains */
58
* contypid links to the pg_type row for a domain if this is a domain
59
* constraint. Otherwise it's 0.
61
* For SQL-style global ASSERTIONs, both conrelid and contypid would be
62
* zero. This is not presently supported, however.
64
Oid contypid; /* domain this constraint constrains */
67
* conindid links to the index supporting the constraint, if any;
68
* otherwise it's 0. This is used for unique, primary-key, and exclusion
69
* constraints, and less obviously for foreign-key constraints (where the
70
* index is a unique index on the referenced relation's referenced
71
* columns). Notice that the index is on conrelid in the first case but
72
* confrelid in the second.
74
Oid conindid; /* index supporting this constraint */
77
* These fields, plus confkey, are only meaningful for a foreign-key
78
* constraint. Otherwise confrelid is 0 and the char fields are spaces.
80
Oid confrelid; /* relation referenced by foreign key */
81
char confupdtype; /* foreign key's ON UPDATE action */
82
char confdeltype; /* foreign key's ON DELETE action */
83
char confmatchtype; /* foreign key's match type */
85
/* Has a local definition (hence, do not drop when coninhcount is 0) */
88
/* Number of times inherited from direct parent relation(s) */
92
* VARIABLE LENGTH FIELDS start here. These fields may be NULL, too.
96
* Columns of conrelid that the constraint applies to, if known (this is
97
* NULL for trigger constraints)
102
* If a foreign key, the referenced columns of confrelid
107
* If a foreign key, the OIDs of the PK = FK equality operators for each
108
* column of the constraint
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)
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)
125
* If an exclusion constraint, the OIDs of the exclusion operators for
126
* each column of the constraint
131
* If a check constraint, nodeToString representation of expression
136
* If a check constraint, source-text representation of expression
139
} FormData_pg_constraint;
142
* Form_pg_constraint corresponds to a pointer to a tuple with
143
* the format of pg_constraint relation.
146
typedef FormData_pg_constraint *Form_pg_constraint;
149
* compiler constants for pg_constraint
152
#define Natts_pg_constraint 23
153
#define Anum_pg_constraint_conname 1
154
#define Anum_pg_constraint_connamespace 2
155
#define Anum_pg_constraint_contype 3
156
#define Anum_pg_constraint_condeferrable 4
157
#define Anum_pg_constraint_condeferred 5
158
#define Anum_pg_constraint_convalidated 6
159
#define Anum_pg_constraint_conrelid 7
160
#define Anum_pg_constraint_contypid 8
161
#define Anum_pg_constraint_conindid 9
162
#define Anum_pg_constraint_confrelid 10
163
#define Anum_pg_constraint_confupdtype 11
164
#define Anum_pg_constraint_confdeltype 12
165
#define Anum_pg_constraint_confmatchtype 13
166
#define Anum_pg_constraint_conislocal 14
167
#define Anum_pg_constraint_coninhcount 15
168
#define Anum_pg_constraint_conkey 16
169
#define Anum_pg_constraint_confkey 17
170
#define Anum_pg_constraint_conpfeqop 18
171
#define Anum_pg_constraint_conppeqop 19
172
#define Anum_pg_constraint_conffeqop 20
173
#define Anum_pg_constraint_conexclop 21
174
#define Anum_pg_constraint_conbin 22
175
#define Anum_pg_constraint_consrc 23
178
/* Valid values for contype */
179
#define CONSTRAINT_CHECK 'c'
180
#define CONSTRAINT_FOREIGN 'f'
181
#define CONSTRAINT_PRIMARY 'p'
182
#define CONSTRAINT_UNIQUE 'u'
183
#define CONSTRAINT_TRIGGER 't'
184
#define CONSTRAINT_EXCLUSION 'x'
187
* Valid values for confupdtype and confdeltype are the FKCONSTR_ACTION_xxx
188
* constants defined in parsenodes.h. Valid values for confmatchtype are
189
* the FKCONSTR_MATCH_xxx constants defined in parsenodes.h.
193
* Identify constraint type for lookup purposes
195
typedef enum ConstraintCategory
199
CONSTRAINT_ASSERTION /* for future expansion */
200
} ConstraintCategory;
203
* prototypes for functions in pg_constraint.c
205
extern Oid CreateConstraintEntry(const char *constraintName,
206
Oid constraintNamespace,
212
const int16 *constraintKey,
217
const int16 *foreignKey,
222
char foreignUpdateType,
223
char foreignDeleteType,
224
char foreignMatchType,
232
extern void RemoveConstraintById(Oid conId);
233
extern void RenameConstraintById(Oid conId, const char *newname);
234
extern void SetValidatedConstraintById(Oid conId);
236
extern bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId,
237
Oid objNamespace, const char *conname);
238
extern char *ChooseConstraintName(const char *name1, const char *name2,
239
const char *label, Oid namespaceid,
242
extern void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId,
243
Oid newNspId, bool isType);
244
extern Oid get_constraint_oid(Oid relid, const char *conname, bool missing_ok);
246
extern bool check_functional_grouping(Oid relid,
247
Index varno, Index varlevelsup,
248
List *grouping_columns,
249
List **constraintDeps);
251
#endif /* PG_CONSTRAINT_H */