constraint
DEFERRABLE
Allows a foreign key check to be postponed until transaction commit. PostgreSQL also supports deferral for certain other constraint types; SQLite supports deferred foreign keys, not general deferred uniqueness. Target: PostgreSQL 17; focused syntax.
Formal Syntax & Structure
sql syntaxsql
REFERENCES parent(id) DEFERRABLE INITIALLY DEFERREDWorking Example
Example Snippetsql
CREATE TABLE parent(id INT PRIMARY KEY NOT NULL); CREATE TABLE child(parent_id INT REFERENCES parent(id) DEFERRABLE INITIALLY DEFERRED);BEGIN;INSERT INTO child VALUES (1);INSERT INTO parent VALUES (1);COMMIT;SELECT parent_id FROM child;