]> granicus.if.org Git - postgresql/blob - src/include/catalog/pg_constraint.h
This patch fixes a bunch of spelling mistakes in comments throughout the
[postgresql] / src / include / catalog / pg_constraint.h
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-2002, PostgreSQL Global Development Group
9  * Portions Copyright (c) 1994, Regents of the University of California
10  *
11  * $Id: pg_constraint.h,v 1.6 2003/03/10 22:28:19 tgl Exp $
12  *
13  * NOTES
14  *        the genbki.sh 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 /* ----------------
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.
26  * ----------------
27  */
28
29 /* ----------------
30  *              pg_constraint definition.  cpp turns this into
31  *              typedef struct FormData_pg_constraint
32  * ----------------
33  */
34 CATALOG(pg_constraint)
35 {
36         /*
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.
44          */
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? */
50
51         /*
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.
55          */
56         Oid                     conrelid;               /* relation this constraint constrains */
57
58         /*
59          * contypid links to the pg_type row for a domain if this is a domain
60          * constraint.  Otherwise it's 0.
61          *
62          * For SQL-style global ASSERTIONs, both conrelid and contypid would be
63          * zero.  This is not presently supported, however.
64          */
65         Oid                     contypid;               /* domain this constraint constrains */
66
67         /*
68          * These fields, plus confkey, are only meaningful for a foreign-key
69          * constraint.  Otherwise confrelid is 0 and the char fields are
70          * spaces.
71          */
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 */
76
77         /*
78          * VARIABLE LENGTH FIELDS start here.  These fields may be NULL, too.
79          */
80
81         /*
82          * Columns of conrelid that the constraint applies to
83          */
84         int2            conkey[1];
85
86         /*
87          * If a foreign key, the referenced columns of confrelid
88          */
89         int2            confkey[1];
90
91         /*
92          * If a check constraint, nodeToString representation of expression
93          */
94         text            conbin;
95
96         /*
97          * If a check constraint, source-text representation of expression
98          */
99         text            consrc;
100 } FormData_pg_constraint;
101
102 /* ----------------
103  *              Form_pg_constraint corresponds to a pointer to a tuple with
104  *              the format of pg_constraint relation.
105  * ----------------
106  */
107 typedef FormData_pg_constraint *Form_pg_constraint;
108
109 /* ----------------
110  *              compiler constants for pg_constraint
111  * ----------------
112  */
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
129
130
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'
136
137 /*
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.
141  */
142
143 /*
144  * Used for constraint support functions where the 
145  * and conrelid, contypid columns being looked up
146  */
147 typedef enum CONSTRAINTCATEGORY {
148         CONSTRAINT_RELATION,
149         CONSTRAINT_DOMAIN,
150         CONSTRAINT_ASSERTION
151 } CONSTRAINTCATEGORY;
152
153 /*
154  * prototypes for functions in pg_constraint.c
155  */
156 extern Oid CreateConstraintEntry(const char *constraintName,
157                                           Oid constraintNamespace,
158                                           char constraintType,
159                                           bool isDeferrable,
160                                           bool isDeferred,
161                                           Oid relId,
162                                           const int16 *constraintKey,
163                                           int constraintNKeys,
164                                           Oid domainId,
165                                           Oid foreignRelId,
166                                           const int16 *foreignKey,
167                                           int foreignNKeys,
168                                           char foreignUpdateType,
169                                           char foreignDeleteType,
170                                           char foreignMatchType,
171                                           Oid indexRelId,
172                                           Node *conExpr,
173                                           const char *conBin,
174                                           const char *conSrc);
175
176 extern void RemoveConstraintById(Oid conId);
177
178 extern bool ConstraintNameIsUsed(CONSTRAINTCATEGORY conCat, Oid objId, Oid objNamespace,
179                                                                  const char *cname);
180 extern char *GenerateConstraintName(CONSTRAINTCATEGORY conCat, Oid objId, Oid objNamespace,
181                                                                         int *counter);
182 extern bool ConstraintNameIsGenerated(const char *cname);
183
184 #endif   /* PG_CONSTRAINT_H */