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

connamename Constraint name (not necessarily unique!)
connamespaceoidpg_namespace.oid The OID of the namespace that contains this constraint
contypechar  'c' = check constraint, 'f' = foreign key constraint, 'p' = primary key constraint, 'u' = unique constraint
condeferrableboolean Is the constraint deferrable?
condeferredboolean Is the constraint deferred by default?
conrelidoidpg_class.oidThe table this constraint is on; 0 if not a table constraint
contypidoidpg_type.oidThe domain this constraint is on; 0 if not a domain constraint
confrelidoidpg_class.oidIf a foreign key, the referenced table; else 0
confupdtypechar Foreign key update action code
confdeltypechar Foreign key deletion action code
confmatchtypechar Foreign key match type
conkeyint2[]pg_attribute.attnumIf a table constraint, list of columns which the constraint constrains
confkeyint2[]pg_attribute.attnumIf a foreign key, list of the referenced columns
conbintext If a check constraint, an internal representation of the expression
consrctext 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.