Re: Mutable foreign key constraints

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Mutable foreign key constraints
Date: 2024-09-14 11:15:01
Message-ID: 02dd7ec5-865a-4099-937c-1abf150dc28c@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 2024-09-12 Th 5:33 PM, Tom Lane wrote:
> I happened to notice that Postgres will let you do
>
> regression=# create table foo (id timestamp primary key);
> CREATE TABLE
> regression=# create table bar (ts timestamptz references foo);
> CREATE TABLE
>
> This strikes me as a pretty bad idea, because whether a particular
> timestamp is equal to a particular timestamptz depends on your
> timezone setting. Thus the constraint could appear to be violated
> after a timezone change.
>
> I'm inclined to propose rejecting FK constraints if the comparison
> operator is not immutable. Among the built-in opclasses, the only
> instances of non-immutable btree equality operators are
>
> regression=# select amopopr::regoperator from pg_amop join pg_operator o on o.oid = amopopr join pg_proc p on p.oid = oprcode where amopmethod=403 and amopstrategy=3 and provolatile != 'i';
> amopopr
> ---------------------------------------------------------
> =(date,timestamp with time zone)
> =(timestamp without time zone,timestamp with time zone)
> =(timestamp with time zone,date)
> =(timestamp with time zone,timestamp without time zone)
> (4 rows)
>
> A possible objection is that if anybody has such a setup and
> hasn't noticed a problem because they never change their
> timezone setting, they might not appreciate us breaking it.
> So I certainly wouldn't propose back-patching this. But
> maybe we should add it as a foot-gun defense going forward.
>
> Thoughts?
>
>

Isn't there an upgrade hazard here? People won't thank us if they can't
now upgrade their clusters. If we can get around that then +1.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mats Kindahl 2024-09-14 12:14:29 Re: Use streaming read API in ANALYZE
Previous Message Tatsuo Ishii 2024-09-14 08:12:01 Re: Add memory/disk usage for WindowAgg nodes in EXPLAIN