DEFERRABLE CONSTRAINT
DEFERRABLE CONSTRAINT is a SQL statement in the Constraints category. PostgreSQL: a constraint that can be checked at COMMIT time instead of immediately (deferred). The syntax is CONSTRAINT name CHECK (condition) DEFERRABLE INITIALLY DEFERRED;. It returns deferred constraint. A typical example: CREATE TABLE accounts (balance DECIMAL CHECK (balance >= 0) DEFERRABLE INITIALLY DEFERRED); BEGIN; UPDATE accounts SET balance = balance - 100 WHERE id = 1; -- Would fail now, but deferred UPDATE accounts SET balance = balance + 100 WHERE id = 2; -- Succeeds COMMIT; -- Check happens here: if net result violates, ROLLBACK -- Useful for circular references or complex inter-row constraints A close relative is PRIMARY KEY, which a column or set of columns that uniquely identifies each row. Only one PK per table. Automatically creates a unique index. A close relative is FOREIGN KEY, which ensures referential integrity: values in this column must exist in the referenced parent table.