14th September 2023: PostgreSQL 16 Released!
Supported Versions: Current (16) / 15 / 14 / 13 / 12 / 11
Development Versions: devel
Unsupported versions: 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 / 8.2 / 8.1 / 8.0 / 7.4 / 7.3
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the current version, or one of the other supported versions listed above instead.

3.10. pg_constraint

This system catalog 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.) See under CREATE TABLE for more information.

Note: NOT NULL constraints are represented in the pg_attribute catalog.

CHECK constraints on domains are stored here, too. Global ASSERTIONS (a currently-unsupported SQL feature) may someday appear here as well.

Table 3-10. 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 boolean   Is the constraint deferrable?
condeferred boolean   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
confdeltype char   Foreign key deletion action code
confmatchtype char   Foreign key match type
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
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: pg_class.relchecks needs to agree with the number of check-constraint entries found in this table for the given relation.