]> granicus.if.org Git - postgresql/blob - src/include/catalog/pg_constraint.h
Add code to extract dependencies from an expression tree, and use it
[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.2 2002/07/16 05:53:34 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 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.
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 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.
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
63          * be 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 spaces.
70          */
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 */
75
76         /*
77          * VARIABLE LENGTH FIELDS start here.  These fields may be NULL, too.
78          */
79
80         /*
81          * Columns of conrelid that the constraint applies to
82          */
83         int2            conkey[1];
84
85         /*
86          * If a foreign key, the referenced columns of confrelid
87          */
88         int2            confkey[1];
89
90         /*
91          * If a check constraint, nodeToString representation of expression
92          */
93         text            conbin;
94
95         /*
96          * If a check constraint, source-text representation of expression
97          */
98         text            consrc;
99 } FormData_pg_constraint;
100
101 /* ----------------
102  *              Form_pg_constraint corresponds to a pointer to a tuple with
103  *              the format of pg_constraint relation.
104  * ----------------
105  */
106 typedef FormData_pg_constraint *Form_pg_constraint;
107
108 /* ----------------
109  *              compiler constants for pg_constraint
110  * ----------------
111  */
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
128
129
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'
135
136 /*
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.
140  */
141
142
143 /*
144  * prototypes for functions in pg_constraint.c
145  */
146 extern Oid      CreateConstraintEntry(const char *constraintName,
147                                                                   Oid constraintNamespace,
148                                                                   char constraintType,
149                                                                   bool isDeferrable,
150                                                                   bool isDeferred,
151                                                                   Oid relId,
152                                                                   const int16 *constraintKey,
153                                                                   int constraintNKeys,
154                                                                   Oid domainId,
155                                                                   Oid foreignRelId,
156                                                                   const int16 *foreignKey,
157                                                                   int foreignNKeys,
158                                                                   char foreignUpdateType,
159                                                                   char foreignDeleteType,
160                                                                   char foreignMatchType,
161                                                                   Node *conExpr,
162                                                                   const char *conBin,
163                                                                   const char *conSrc);
164
165 extern void RemoveConstraintById(Oid conId);
166
167 extern bool ConstraintNameIsUsed(Oid relId, Oid relNamespace,
168                                                                  const char *cname);
169 extern char *GenerateConstraintName(Oid relId, Oid relNamespace,
170                                                                         int *counter);
171 extern bool ConstraintNameIsGenerated(const char *cname);
172
173 #endif   /* PG_CONSTRAINT_H */