ERROR: current transaction is aborted, queries ignored until end of transaction block
COMMIT;
DROP TABLE fktable, pktable;
+-- deferrable, initially deferred
+CREATE TABLE pktable (
+ id INT4 PRIMARY KEY,
+ other INT4
+);
+NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "pktable_pkey" for table "pktable"
+CREATE TABLE fktable (
+ id INT4 PRIMARY KEY,
+ fk INT4 REFERENCES pktable DEFERRABLE INITIALLY DEFERRED
+);
+NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "fktable_pkey" for table "fktable"
+NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
+BEGIN;
+-- no error here
+INSERT INTO fktable VALUES (100, 200);
+-- error here on commit
+COMMIT;
+ERROR: insert or update on "fktable" violates foreign key constraint "$1"
+DETAIL: Key (fk)=(200) is not present in "pktable".
COMMIT;
DROP TABLE fktable, pktable;
+
+-- deferrable, initially deferred
+CREATE TABLE pktable (
+ id INT4 PRIMARY KEY,
+ other INT4
+);
+
+CREATE TABLE fktable (
+ id INT4 PRIMARY KEY,
+ fk INT4 REFERENCES pktable DEFERRABLE INITIALLY DEFERRED
+);
+
+BEGIN;
+
+-- no error here
+INSERT INTO fktable VALUES (100, 200);
+
+-- error here on commit
+COMMIT;
+