]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix FK triggers losing DEFERRABLE/INITIALLY DEFERRED when marked ENFORCED again
authorFujii Masao <fujii@postgresql.org>
Mon, 30 Mar 2026 05:37:33 +0000 (14:37 +0900)
committerFujii Masao <fujii@postgresql.org>
Mon, 30 Mar 2026 05:38:58 +0000 (14:38 +0900)
commit5db5e339692ed98adb5ae6ff625a92b49f770a6f
tree3a29064a3e4a306344f3a6fb4a7d70d5d4fa8557
parent49315de0c0743cd5ecddf3af15217a6e7ec3fdb0
Fix FK triggers losing DEFERRABLE/INITIALLY DEFERRED when marked ENFORCED again

Previously, a foreign key defined as DEFERRABLE INITIALLY DEFERRED could
behave as NOT DEFERRABLE after being set to NOT ENFORCED and then back
to ENFORCED.

This happened because recreating the FK triggers on re-enabling the constraint
forgot to restore the tgdeferrable and tginitdeferred fields in pg_trigger.

Fix this bug by properly setting those fields when the foreign key constraint
is marked ENFORCED again and its triggers are recreated, so the original
DEFERRABLE and INITIALLY DEFERRED properties are preserved.

Backpatch to v18, where NOT ENFORCED foreign keys were introduced.

Author: Yasuo Honda <yasuo.honda@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CAKmOUTms2nkxEZDdcrsjq5P3b2L_PR266Hv8kW5pANwmVaRJJQ@mail.gmail.com
Backpatch-through: 18
src/backend/commands/tablecmds.c
src/test/regress/expected/foreign_key.out
src/test/regress/sql/foreign_key.sql