Created
March 23, 2026 23:23
-
-
Save yahonda/3220c859c5c9cd6ec9cee17602f84ee9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #4 Patched PostgreSQL : NOT ENFORCED -> ENFORCED restires pg_trigger tgdeferrable and tginitdeferred value to t | |
| ``` | |
| postgres=# select version(); | |
| version | |
| -------------------------------------------------------------------- | |
| PostgreSQL 19devel on x86_64-linux, compiled by gcc-15.2.1, 64-bit | |
| (1 row) | |
| postgres=# CREATE TABLE parent ( | |
| postgres(# id INTEGER PRIMARY KEY, | |
| postgres(# name TEXT NOT NULL | |
| postgres(# ); | |
| CREATE TABLE | |
| postgres=# CREATE TABLE child ( | |
| postgres(# id INT PRIMARY KEY, | |
| postgres(# parent_id INT, | |
| postgres(# CONSTRAINT child_parent_fk | |
| postgres(# FOREIGN KEY (parent_id) | |
| postgres(# REFERENCES parent(id) | |
| postgres(# DEFERRABLE INITIALLY DEFERRED | |
| postgres(# ); | |
| CREATE TABLE | |
| postgres=# SELECT | |
| postgres-# conname, | |
| postgres-# condeferrable, | |
| postgres-# condeferred | |
| postgres-# FROM pg_constraint | |
| postgres-# WHERE conname = 'child_parent_fk'; | |
| conname | condeferrable | condeferred | |
| -----------------+---------------+------------- | |
| child_parent_fk | t | t | |
| (1 row) | |
| postgres=# SELECT | |
| postgres-# tgname, | |
| postgres-# tgdeferrable, | |
| postgres-# tginitdeferred | |
| postgres-# FROM pg_trigger | |
| postgres-# WHERE tgname LIKE 'RI_ConstraintTrigger%'; | |
| tgname | tgdeferrable | tginitdeferred | |
| ------------------------------+--------------+---------------- | |
| RI_ConstraintTrigger_a_16404 | t | t | |
| RI_ConstraintTrigger_a_16405 | t | t | |
| RI_ConstraintTrigger_c_16406 | t | t | |
| RI_ConstraintTrigger_c_16407 | t | t | |
| (4 rows) | |
| postgres=# ALTER TABLE child ALTER CONSTRAINT child_parent_fk NOT ENFORCED; | |
| ALTER TABLE | |
| postgres=# ALTER TABLE child ALTER CONSTRAINT child_parent_fk ENFORCED; | |
| ALTER TABLE | |
| postgres=# SELECT | |
| postgres-# conname, | |
| postgres-# condeferrable, | |
| postgres-# condeferred | |
| postgres-# FROM pg_constraint | |
| postgres-# WHERE conname = 'child_parent_fk'; | |
| conname | condeferrable | condeferred | |
| -----------------+---------------+------------- | |
| child_parent_fk | t | t | |
| (1 row) | |
| postgres=# SELECT | |
| postgres-# tgname, | |
| postgres-# tgdeferrable, | |
| postgres-# tginitdeferred | |
| postgres-# FROM pg_trigger | |
| postgres-# WHERE tgname LIKE 'RI_ConstraintTrigger%'; | |
| tgname | tgdeferrable | tginitdeferred | |
| ------------------------------+--------------+---------------- | |
| RI_ConstraintTrigger_a_16408 | t | t | |
| RI_ConstraintTrigger_a_16409 | t | t | |
| RI_ConstraintTrigger_c_16410 | t | t | |
| RI_ConstraintTrigger_c_16411 | t | t | |
| (4 rows) | |
| postgres=# BEGIN; | |
| BEGIN | |
| postgres=*# SET CONSTRAINTS child_parent_fk DEFERRED; | |
| SET CONSTRAINTS | |
| postgres=*# INSERT INTO child (id, parent_id) VALUES (1, 999); | |
| INSERT 0 1 | |
| postgres=*# COMMIT; | |
| ERROR: insert or update on table "child" violates foreign key constraint "child_parent_fk" | |
| DETAIL: Key (parent_id)=(999) is not present in table "parent". | |
| postgres=# | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment