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.2 2002/07/16 05:53:34 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 definintions 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 obtain
41 * a global lock to generate a globally unique name for a nameless
42 * constraint. We associate a namespace with constraint names only
43 * 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
63 * be 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 spaces.
71 Oid confrelid; /* relation referenced by foreign key */
72 char confupdtype; /* foreign key's ON UPDATE action */
73 char confdeltype; /* foreign key's ON DELETE action */
74 char confmatchtype; /* foreign key's match type */
77 * VARIABLE LENGTH FIELDS start here. These fields may be NULL, too.
81 * Columns of conrelid that the constraint applies to
86 * If a foreign key, the referenced columns of confrelid
91 * If a check constraint, nodeToString representation of expression
96 * If a check constraint, source-text representation of expression
99 } FormData_pg_constraint;
102 * Form_pg_constraint corresponds to a pointer to a tuple with
103 * the format of pg_constraint relation.
106 typedef FormData_pg_constraint *Form_pg_constraint;
109 * compiler constants for pg_constraint
112 #define Natts_pg_constraint 15
113 #define Anum_pg_constraint_conname 1
114 #define Anum_pg_constraint_connamespace 2
115 #define Anum_pg_constraint_contype 3
116 #define Anum_pg_constraint_condeferrable 4
117 #define Anum_pg_constraint_condeferred 5
118 #define Anum_pg_constraint_conrelid 6
119 #define Anum_pg_constraint_contypid 7
120 #define Anum_pg_constraint_confrelid 8
121 #define Anum_pg_constraint_confupdtype 9
122 #define Anum_pg_constraint_confdeltype 10
123 #define Anum_pg_constraint_confmatchtype 11
124 #define Anum_pg_constraint_conkey 12
125 #define Anum_pg_constraint_confkey 13
126 #define Anum_pg_constraint_conbin 14
127 #define Anum_pg_constraint_consrc 15
130 /* Valid values for contype */
131 #define CONSTRAINT_CHECK 'c'
132 #define CONSTRAINT_FOREIGN 'f'
133 #define CONSTRAINT_PRIMARY 'p'
134 #define CONSTRAINT_UNIQUE 'u'
137 * Valid values for confupdtype and confdeltype are the FKCONSTR_ACTION_xxx
138 * constants defined in parsenodes.h. Valid values for confmatchtype are
139 * the FKCONSTR_MATCH_xxx constants defined in parsenodes.h.
144 * prototypes for functions in pg_constraint.c
146 extern Oid CreateConstraintEntry(const char *constraintName,
147 Oid constraintNamespace,
152 const int16 *constraintKey,
156 const int16 *foreignKey,
158 char foreignUpdateType,
159 char foreignDeleteType,
160 char foreignMatchType,
165 extern void RemoveConstraintById(Oid conId);
167 extern bool ConstraintNameIsUsed(Oid relId, Oid relNamespace,
169 extern char *GenerateConstraintName(Oid relId, Oid relNamespace,
171 extern bool ConstraintNameIsGenerated(const char *cname);
173 #endif /* PG_CONSTRAINT_H */