1 /*-------------------------------------------------------------------------
4 * definition of the system "constraint" relation (pg_constraint)
5 * along with the relation's initial contents.
8 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1994, Regents of the University of California
11 * $Id: pg_constraint.h,v 1.6 2003/03/10 22:28:19 tgl Exp $
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
23 * postgres.h contains the system type definitions and the
24 * CATALOG(), BOOTSTRAP and DATA() sugar words so this file
25 * can be read by both genbki.sh and the C compiler.
30 * pg_constraint definition. cpp turns this into
31 * typedef struct FormData_pg_constraint
34 CATALOG(pg_constraint)
37 * conname + connamespace is deliberately not unique; we allow, for
38 * example, the same name to be used for constraints of different
39 * relations. This is partly for backwards compatibility with past
40 * Postgres practice, and partly because we don't want to have to
41 * obtain a global lock to generate a globally unique name for a
42 * nameless constraint. We associate a namespace with constraint
43 * names only for SQL92 compatibility.
45 NameData conname; /* name of this constraint */
46 Oid connamespace; /* OID of namespace containing constraint */
47 char contype; /* constraint type; see codes below */
48 bool condeferrable; /* deferrable constraint? */
49 bool condeferred; /* deferred by default? */
52 * conrelid and conkey are only meaningful if the constraint applies
53 * to a specific relation (this excludes domain constraints and
54 * assertions). Otherwise conrelid is 0 and conkey is NULL.
56 Oid conrelid; /* relation this constraint constrains */
59 * contypid links to the pg_type row for a domain if this is a domain
60 * constraint. Otherwise it's 0.
62 * For SQL-style global ASSERTIONs, both conrelid and contypid would be
63 * zero. This is not presently supported, however.
65 Oid contypid; /* domain this constraint constrains */
68 * These fields, plus confkey, are only meaningful for a foreign-key
69 * constraint. Otherwise confrelid is 0 and the char fields are
72 Oid confrelid; /* relation referenced by foreign key */
73 char confupdtype; /* foreign key's ON UPDATE action */
74 char confdeltype; /* foreign key's ON DELETE action */
75 char confmatchtype; /* foreign key's match type */
78 * VARIABLE LENGTH FIELDS start here. These fields may be NULL, too.
82 * Columns of conrelid that the constraint applies to
87 * If a foreign key, the referenced columns of confrelid
92 * If a check constraint, nodeToString representation of expression
97 * If a check constraint, source-text representation of expression
100 } FormData_pg_constraint;
103 * Form_pg_constraint corresponds to a pointer to a tuple with
104 * the format of pg_constraint relation.
107 typedef FormData_pg_constraint *Form_pg_constraint;
110 * compiler constants for pg_constraint
113 #define Natts_pg_constraint 15
114 #define Anum_pg_constraint_conname 1
115 #define Anum_pg_constraint_connamespace 2
116 #define Anum_pg_constraint_contype 3
117 #define Anum_pg_constraint_condeferrable 4
118 #define Anum_pg_constraint_condeferred 5
119 #define Anum_pg_constraint_conrelid 6
120 #define Anum_pg_constraint_contypid 7
121 #define Anum_pg_constraint_confrelid 8
122 #define Anum_pg_constraint_confupdtype 9
123 #define Anum_pg_constraint_confdeltype 10
124 #define Anum_pg_constraint_confmatchtype 11
125 #define Anum_pg_constraint_conkey 12
126 #define Anum_pg_constraint_confkey 13
127 #define Anum_pg_constraint_conbin 14
128 #define Anum_pg_constraint_consrc 15
131 /* Valid values for contype */
132 #define CONSTRAINT_CHECK 'c'
133 #define CONSTRAINT_FOREIGN 'f'
134 #define CONSTRAINT_PRIMARY 'p'
135 #define CONSTRAINT_UNIQUE 'u'
138 * Valid values for confupdtype and confdeltype are the FKCONSTR_ACTION_xxx
139 * constants defined in parsenodes.h. Valid values for confmatchtype are
140 * the FKCONSTR_MATCH_xxx constants defined in parsenodes.h.
144 * Used for constraint support functions where the
145 * and conrelid, contypid columns being looked up
147 typedef enum CONSTRAINTCATEGORY {
151 } CONSTRAINTCATEGORY;
154 * prototypes for functions in pg_constraint.c
156 extern Oid CreateConstraintEntry(const char *constraintName,
157 Oid constraintNamespace,
162 const int16 *constraintKey,
166 const int16 *foreignKey,
168 char foreignUpdateType,
169 char foreignDeleteType,
170 char foreignMatchType,
176 extern void RemoveConstraintById(Oid conId);
178 extern bool ConstraintNameIsUsed(CONSTRAINTCATEGORY conCat, Oid objId, Oid objNamespace,
180 extern char *GenerateConstraintName(CONSTRAINTCATEGORY conCat, Oid objId, Oid objNamespace,
182 extern bool ConstraintNameIsGenerated(const char *cname);
184 #endif /* PG_CONSTRAINT_H */