~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/include/catalog/pg_constraint.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2011, PostgreSQL Global Development Group
 
9
 * Portions Copyright (c) 1994, Regents of the University of California
 
10
 *
 
11
 * src/include/catalog/pg_constraint.h
 
12
 *
 
13
 * NOTES
 
14
 *        the genbki.pl 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
#include "catalog/genbki.h"
 
23
#include "nodes/pg_list.h"
 
24
 
 
25
/* ----------------
 
26
 *              pg_constraint definition.  cpp turns this into
 
27
 *              typedef struct FormData_pg_constraint
 
28
 * ----------------
 
29
 */
 
30
#define ConstraintRelationId  2606
 
31
 
 
32
CATALOG(pg_constraint,2606)
 
33
{
 
34
        /*
 
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.
 
42
         */
 
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? */
 
49
 
 
50
        /*
 
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.
 
54
         */
 
55
        Oid                     conrelid;               /* relation this constraint constrains */
 
56
 
 
57
        /*
 
58
         * contypid links to the pg_type row for a domain if this is a domain
 
59
         * constraint.  Otherwise it's 0.
 
60
         *
 
61
         * For SQL-style global ASSERTIONs, both conrelid and contypid would be
 
62
         * zero. This is not presently supported, however.
 
63
         */
 
64
        Oid                     contypid;               /* domain this constraint constrains */
 
65
 
 
66
        /*
 
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.
 
73
         */
 
74
        Oid                     conindid;               /* index supporting this constraint */
 
75
 
 
76
        /*
 
77
         * These fields, plus confkey, are only meaningful for a foreign-key
 
78
         * constraint.  Otherwise confrelid is 0 and the char fields are spaces.
 
79
         */
 
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 */
 
84
 
 
85
        /* Has a local definition (hence, do not drop when coninhcount is 0) */
 
86
        bool            conislocal;
 
87
 
 
88
        /* Number of times inherited from direct parent relation(s) */
 
89
        int4            coninhcount;
 
90
 
 
91
        /*
 
92
         * VARIABLE LENGTH FIELDS start here.  These fields may be NULL, too.
 
93
         */
 
94
 
 
95
        /*
 
96
         * Columns of conrelid that the constraint applies to, if known (this is
 
97
         * NULL for trigger constraints)
 
98
         */
 
99
        int2            conkey[1];
 
100
 
 
101
        /*
 
102
         * If a foreign key, the referenced columns of confrelid
 
103
         */
 
104
        int2            confkey[1];
 
105
 
 
106
        /*
 
107
         * If a foreign key, the OIDs of the PK = FK equality operators for each
 
108
         * column of the constraint
 
109
         */
 
110
        Oid                     conpfeqop[1];
 
111
 
 
112
        /*
 
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)
 
115
         */
 
116
        Oid                     conppeqop[1];
 
117
 
 
118
        /*
 
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)
 
121
         */
 
122
        Oid                     conffeqop[1];
 
123
 
 
124
        /*
 
125
         * If an exclusion constraint, the OIDs of the exclusion operators for
 
126
         * each column of the constraint
 
127
         */
 
128
        Oid                     conexclop[1];
 
129
 
 
130
        /*
 
131
         * If a check constraint, nodeToString representation of expression
 
132
         */
 
133
        pg_node_tree conbin;
 
134
 
 
135
        /*
 
136
         * If a check constraint, source-text representation of expression
 
137
         */
 
138
        text            consrc;
 
139
} FormData_pg_constraint;
 
140
 
 
141
/* ----------------
 
142
 *              Form_pg_constraint corresponds to a pointer to a tuple with
 
143
 *              the format of pg_constraint relation.
 
144
 * ----------------
 
145
 */
 
146
typedef FormData_pg_constraint *Form_pg_constraint;
 
147
 
 
148
/* ----------------
 
149
 *              compiler constants for pg_constraint
 
150
 * ----------------
 
151
 */
 
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
 
176
 
 
177
 
 
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'
 
185
 
 
186
/*
 
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.
 
190
 */
 
191
 
 
192
/*
 
193
 * Identify constraint type for lookup purposes
 
194
 */
 
195
typedef enum ConstraintCategory
 
196
{
 
197
        CONSTRAINT_RELATION,
 
198
        CONSTRAINT_DOMAIN,
 
199
        CONSTRAINT_ASSERTION            /* for future expansion */
 
200
} ConstraintCategory;
 
201
 
 
202
/*
 
203
 * prototypes for functions in pg_constraint.c
 
204
 */
 
205
extern Oid CreateConstraintEntry(const char *constraintName,
 
206
                                          Oid constraintNamespace,
 
207
                                          char constraintType,
 
208
                                          bool isDeferrable,
 
209
                                          bool isDeferred,
 
210
                                          bool isValidated,
 
211
                                          Oid relId,
 
212
                                          const int16 *constraintKey,
 
213
                                          int constraintNKeys,
 
214
                                          Oid domainId,
 
215
                                          Oid indexRelId,
 
216
                                          Oid foreignRelId,
 
217
                                          const int16 *foreignKey,
 
218
                                          const Oid *pfEqOp,
 
219
                                          const Oid *ppEqOp,
 
220
                                          const Oid *ffEqOp,
 
221
                                          int foreignNKeys,
 
222
                                          char foreignUpdateType,
 
223
                                          char foreignDeleteType,
 
224
                                          char foreignMatchType,
 
225
                                          const Oid *exclOp,
 
226
                                          Node *conExpr,
 
227
                                          const char *conBin,
 
228
                                          const char *conSrc,
 
229
                                          bool conIsLocal,
 
230
                                          int conInhCount);
 
231
 
 
232
extern void RemoveConstraintById(Oid conId);
 
233
extern void RenameConstraintById(Oid conId, const char *newname);
 
234
extern void SetValidatedConstraintById(Oid conId);
 
235
 
 
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,
 
240
                                         List *others);
 
241
 
 
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);
 
245
 
 
246
extern bool check_functional_grouping(Oid relid,
 
247
                                                  Index varno, Index varlevelsup,
 
248
                                                  List *grouping_columns,
 
249
                                                  List **constraintDeps);
 
250
 
 
251
#endif   /* PG_CONSTRAINT_H */