pg_constraint
The pg_constraint system catalog table 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 table.
Check constraints on domains are stored here, too.
| Column | Type | References | Description |
|---|---|---|---|
conname |
name |
— |
Constraint name (not necessarily unique) |
connamespace |
oid |
pg_namespace.oid |
The OID of the namespace (schema) that contains this constraint |
contype |
char |
— |
|
condeferrable |
boolean |
— |
Indicates whether the constraint is deferrable |
condeferred |
boolean |
— |
Indicates whether the constraint is deferred by default |
convalidated |
boolean |
— |
Indicates whether the constraint has been validated.
Currently, can only be |
conrelid |
oid |
pg_class.oid |
The table this constraint is on; |
contypid |
oid |
pg_type.oid |
The domain this constraint is on; |
conindid |
oid |
pg_class.oid |
The index supporting this constraint, if it is a unique, primary key, or foreign key constraint; else |
confrelid |
oid |
pg_class.oid |
If a foreign key, the referenced table; else |
confupdtype |
char |
— |
Foreign key update action code |
confdeltype |
char |
— |
Foreign key deletion action code |
confmatchtype |
char |
— |
Foreign key match type |
conislocal |
boolean |
— |
This constraint is defined locally for the relation. Note that a constraint can be locally defined and inherited simultaneously |
coninhcount |
integer |
— |
The number of direct inheritance descendants this constraint has. A constraint with a nonzero number of descendants cannot be dropped nor renamed |
connoinherit |
boolean |
— |
Indicates if the constraint is local and cannot be inherited by child tables |
conkey |
int2[] |
pg_attribute.attnum |
If a table constraint, list of columns which the constraint constrains |
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 |
conexclop |
oid[] |
pg_operator.oid |
If an exclusion constraint, list of the per-column exclusion operators |
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 |