From 1772d554b089c4779eaa13ae1487721e3080d119 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 21 Jan 2025 14:34:44 +0100 Subject: Fix NO ACTION temporal foreign keys when the referenced endpoints change If a referenced UPDATE changes the temporal start/end times, shrinking the span the row is valid, we get a false return from ri_Check_Pk_Match(), but overlapping references may still be valid, if their reference didn't overlap with the removed span. We need to consider what span(s) are still provided in the referenced table. Instead of returning that from ri_Check_Pk_Match(), we can just look it up in the main SQL query. Reported-by: Sam Gabrielsson Author: Paul Jungwirth Discussion: https://www.postgresql.org/message-id/flat/CA+renyUApHgSZF9-nd-a0+OPGharLQLO=mDHcY4_qQ0+noCUVg@mail.gmail.com --- src/backend/commands/tablecmds.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/backend/commands/tablecmds.c') diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index d2420a9558c..4117a0ab1a6 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -10260,8 +10260,10 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel, { Oid periodoperoid; Oid aggedperiodoperoid; + Oid intersectoperoid; - FindFKPeriodOpers(opclasses[numpks - 1], &periodoperoid, &aggedperiodoperoid); + FindFKPeriodOpers(opclasses[numpks - 1], &periodoperoid, &aggedperiodoperoid, + &intersectoperoid); } /* First, create the constraint catalog entry itself. */ -- cgit v1.2.3