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 43-13. pg_constraint Columns
|Constraint name (not necessarily unique!)
|The OID of the namespace that contains this constraint
|c = check constraint, f = foreign key constraint, p = primary key constraint, u = unique constraint
|Is the constraint deferrable?
|Is the constraint deferred by default?
|The table this constraint is on; 0 if not a table constraint
|The domain this constraint is on; 0 if not a domain constraint
|If a foreign key, the referenced table; else 0
|Foreign key update action code
|Foreign key deletion action code
|Foreign key match type
|If a table constraint, list of columns which the constraint constrains
|If a foreign key, list of the referenced columns
|If a check constraint, an internal representation of the expression
|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 the given relation.