PostgreSQL 8.4.21 Documentation | ||||
---|---|---|---|---|
Prev | Fast Backward | Chapter 44. System Catalogs | Fast Forward | Next |
The catalog pg_constraint stores check, primary key, unique, and foreign key constraints on tables. (Column constraints are not treated specially. Every column constraint is equivalent to some table constraint.) Not-null constraints are represented in the pg_attribute catalog.
Check constraints on domains are stored here, too.
Table 44-12. pg_constraint Columns
Name | Type | References | Description |
---|---|---|---|
conname | name | Constraint name (not necessarily unique!) | |
connamespace | oid | pg_namespace.oid | The OID of the namespace that contains this constraint |
contype | char | c = check constraint, f = foreign key constraint, p = primary key constraint, u = unique constraint | |
condeferrable | bool | Is the constraint deferrable? | |
condeferred | bool | Is the constraint deferred by default? | |
conrelid | oid | pg_class.oid | The table this constraint is on; 0 if not a table constraint |
contypid | oid | pg_type.oid | The domain this constraint is on; 0 if not a domain constraint |
confrelid | oid | pg_class.oid | If a foreign key, the referenced table; else 0 |
confupdtype | char | Foreign key update action code: a = no action, r = restrict, c = cascade, n = set null, d = set default | |
confdeltype | char | Foreign key deletion action code: a = no action, r = restrict, c = cascade, n = set null, d = set default | |
confmatchtype | char | Foreign key match type: f = full, p = partial, u = simple (unspecified) | |
conislocal | bool | This constraint is defined locally in the relation. Note that a constraint can be locally defined and inherited simultaneously | |
coninhcount | int4 | The number of direct ancestors this constraint has. A constraint with a nonzero number of ancestors cannot be dropped nor renamed | |
conkey | int2[] | pg_attribute.attnum | If a table constraint (including a foreign key), list of the constrained columns |
confkey | int2[] | pg_attribute.attnum | If a foreign key, list of the referenced columns |
conpfeqop | oid[] | pg_operator.oid | If a foreign key, list of the equality operators for PK = FK comparisons |
conppeqop | oid[] | pg_operator.oid | If a foreign key, list of the equality operators for PK = PK comparisons |
conffeqop | oid[] | pg_operator.oid | If a foreign key, list of the equality operators for FK = FK comparisons |
conbin | text | If a check constraint, an internal representation of the expression | |
consrc | text | If a check constraint, a human-readable representation of the expression |
Note: consrc is not updated when referenced objects change; for example, it won't track renaming of columns. Rather than relying on this field, it's best to use
pg_get_constraintdef()
to extract the definition of a check constraint.
Note: pg_class.relchecks needs to agree with the number of check-constraint entries found in this table for each relation.