How do I implement circular constraints in PostgreSQL? <p>I want to enforce that a row in one table must have a matching row in another table, and vice versa. I'm currently doing it like this to work around the fact that you can't REFERENCE a table that hasn't been created yet. Is there a more natural way that I'm not aware of?</p> <pre><code>CREATE TABLE LE (id int PRIMARY KEY); CREATE TABLE LE_TYP (id int PRIMARY KEY, typ text); ALTER TABLE LE ADD CONSTRAINT twowayref FOREIGN KEY (id) REFERENCES LE_TYP (id) DEFERRABLE INITIALLY DEFERRED; ALTER TABLE LE_TYP ADD CONSTRAINT twowayref_rev FOREIGN KEY (id) REFERENCES LE (id) DEFERRABLE INITIALLY DEFERRED; </code></pre>