Re: BUG #18295: In PostgreSQL a unique index on targeted columns is sufficient to support a foreign key

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: gparc(at)free(dot)fr, 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-26 11:33:20
Message-ID: CAApHDvoaMq1oGxJbfVK4Miwp=0DbhuTJhkUuYOw-Q=WkOmH-qQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, 26 Jan 2024 at 23:55, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> wrote:
> Attached is my suggested patch.

Why did you choose to remove the mention of primary key and unique
constraints in:

+++ b/doc/src/sgml/ddl.sgml
@@ -1317,9 +1317,7 @@ CREATE TABLE posts (
</para>

<para>
- 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);
+ A foreign key must reference columns on which a unique index in defined,

but choose to keep them here:

+++ b/doc/src/sgml/ref/create_table.sgml
@@ -1166,7 +1166,7 @@ WITH ( MODULUS <replaceable
class="parameter">numeric_literal</replaceable>, REM
class="parameter">refcolumn</replaceable> list is omitted, the
primary key of the <replaceable class="parameter">reftable</replaceable>
is used. The referenced columns must be the columns of a non-deferrable
- unique or primary key constraint in the referenced table. The user
+ unique or primary key constraint or a unique index in the
referenced table. The user

I'd rather we continue to mention primary keys and unique constraints
in ddl.sgml. It just seems good practice to me to define a constraint
and it seems better if people continue to do that to increase the
likelihood that their schema is compatible with another RDBMS.

David

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David Rowley 2024-01-26 12:02:29 Re: BUG #18305: Unexpected error: "WindowFunc not found in subplan target lists" triggered by subqueries
Previous Message Laurenz Albe 2024-01-26 10:54:52 Re: BUG #18295: In PostgreSQL a unique index on targeted columns is sufficient to support a foreign key