From: | gparc(at)free(dot)fr |
---|---|
To: | pgsql-bugs <pgsql-bugs(at)lists(dot)postgresql(dot)org> |
Subject: | Re: BUG #18295: In PostgreSQL a unique index on targeted columns is sufficient to support a foreign key |
Date: | 2024-01-24 10:11:17 |
Message-ID: | 1142099713.208806083.1706091077854.JavaMail.zimbra@free.fr |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Hello,
any comment ?
Regards
----- Mail original -----
De: "PG Bug reporting form" <noreply(at)postgresql(dot)org>
À: "pgsql-bugs" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Cc: "gparc" <gparc(at)online(dot)fr>
Envoyé: Lundi 15 Janvier 2024 12:37:19
Objet: BUG #18295: In PostgreSQL a unique index on targeted columns is sufficient to support a foreign key
The following bug has been logged on the website:
Bug reference: 18295
Logged by: Gilles PARC
Email address: gparc(at)online(dot)fr
PostgreSQL version: 16.1
Operating system: Linux
Description:
Hello,
coming from Oracle, I'm surprised to see that in PostgreSQL, a foreign key
can be linked to a unique index
on the target table and not exclusively to a primary key constraint or
UNIQUE constraint.
Even if a primary/unique constraint implies the creation of a unique index,
semantically, it's not the same.
In Oracle, in that case (only unique index on targeted columns), we get the
following error :
ORA-02270: no matching unique or primary key for this column-list
Reading the PostgreSQL documentation, I found this snippet in Chapter 5.4
(https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-FK)
:
"A foreign key must reference columns that either are a primary key or form
a unique constraint. This means that the referenced columns always have an
index (the one underlying the primary key or unique constraint);"
which seems to suggest that in PostgreSQL also a foreign key should refer to
a primary/unique constraint on the target table.
Is it a bug or an intended feature ? If the latter, I think the doc should
be amended to remove any ambiguity.
Regards
P.S. by the way, I don't know what the SQL standard states about that.
From | Date | Subject | |
---|---|---|---|
Next Message | feichanghong | 2024-01-24 11:01:44 | Re: BUG #18280: logical decoding build wrong snapshot for subtransactions |
Previous Message | Hayato Kuroda (Fujitsu) | 2024-01-24 10:00:09 | RE: BUG #18280: logical decoding build wrong snapshot for subtransactions |