begin;
CREATE TABLE test (
	id INTEGER,
	parent_id INTEGER NULL REFERENCES test(id),
	PRIMARY KEY(id)
);

CREATE TABLE a (
       ac INTEGER REFERENCES test(id) DEFERRABLE
);

INSERT INTO test(id, parent_id) VALUES(10, null);
INSERT INTO test(id, parent_id) VALUES(20, 10);

CREATE TABLE test3(
       n integer,
       primary key(n)
);
INSERT INTO test3 VALUES(1);

CREATE TABLE test2(
       id2 INTEGER,
       a TIMESTAMP,
       n INTEGER REFERENCES test3 ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED,
       PRIMARY KEY (id2)
);
INSERT INTO test2(id2, n) VALUES(1, 1);

UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;
UPDATE test2 SET a=NOW() WHERE id2=1;

SET CONSTRAINTS ALL IMMEDIATE;
SAVEPOINT lala;
SET CONSTRAINTS ALL DEFERRED;
DELETE FROM test WHERE id=20;
ROLLBACK TO SAVEPOINT lala;
RELEASE SAVEPOINT lala;
SET CONSTRAINTS ALL IMMEDIATE;
rollback;