Re: SQL:2011 application time

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>
Cc: jian he <jian(dot)universality(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, vignesh C <vignesh21(at)gmail(dot)com>
Subject: Re: SQL:2011 application time
Date: 2025-02-13 13:23:25
Message-ID: 3e061027-781d-42c1-b6e8-bafbf3b51033@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 23.01.25 16:40, Peter Eisentraut wrote:
> I think my interpretation of what RESTRICT should do is different.
>
> The clause "Execution of referential actions" in the SQL standard only
> talks about referenced and referencing columns, not periods.  So this
> would mean you can change the period columns all you want (as long as
> they maintain referential integrity).  So it would be like the NO ACTION
> case.  But you can't change any of the non-period columns on the primary
> key if they are referenced by any referencing columns, even if the
> respective periods are disjoint.
>
> Maybe this makes sense, or maybe this is a mistake (neglected to update
> this part when periods were introduced?).  But in any case, I can't get
> from this to what the patch does.  When I apply the tests in the patch
> without the code changes, what I would intuitively like are more errors
> than the starting state, but your patch results in fewer errors.

After staring at this a bit more, I think my interpretation above was
not correct. This seems better:

The clause "Execution of referential actions" in the SQL standard only
talks about referenced and referencing columns, not periods. The
RESTRICT error is raised when a "matching row" exists in the referencing
table. The "matching row" is determined purely by looking at the
"normal" columns of the key, not the period columns.

So in our implementation in ri_restrict(), ISTM, we just need to ignore
the period/range columns when doing the RESTRICT check.

Attached is a quick patch that demonstrates how this could work. I
think the semantics of this are right and make sense.

Attachment Content-Type Size
0001-WIP-Fix-RESTRICT-behavior-for-temporal-foreign-keys.patch.nocfbot text/plain 1.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Aleksander Alekseev 2025-02-13 13:23:52 Re: Elimination of the repetitive code at the SLRU bootstrap functions.
Previous Message Álvaro Herrera 2025-02-13 13:21:33 Re: Elimination of the repetitive code at the SLRU bootstrap functions.