Re: BUG #18295: In PostgreSQL a unique index on targeted columns is sufficient to support a foreign key - Mailing list pgsql-bugs

From Laurenz Albe
Subject Re: BUG #18295: In PostgreSQL a unique index on targeted columns is sufficient to support a foreign key
Date
Msg-id 763b0bc3828415afa5f815753100722611faa1e9.camel@cybertec.at
Whole thread Raw
In response to Re: BUG #18295: In PostgreSQL a unique index on targeted columns is sufficient to support a foreign key  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: BUG #18295: In PostgreSQL a unique index on targeted columns is sufficient to support a foreign key  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-bugs
On Sat, 2024-01-27 at 00:33 +1300, David Rowley wrote:
> On Fri, 26 Jan 2024 at 23:55, Laurenz Albe <laurenz.albe@cybertec.at> wrote:
> > Attached is my suggested patch.
>
> Why did you choose to remove the mention of primary key and unique
> constraints in:
>
> -    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:
>
> -      unique or primary key constraint in the referenced table.  The user
> +      unique or primary key constraint or a unique index in the
>
> 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.

I removed the mention of constraints for simplicity, but I agree that the
documentation should encourage users to reference constraints.

Attached is a modified patch.

Yours,
Laurenz Albe

Attachment

pgsql-bugs by date:

Previous
From: David Rowley
Date:
Subject: Re: BUG #18305: Unexpected error: "WindowFunc not found in subplan target lists" triggered by subqueries
Next
From: PG Bug reporting form
Date:
Subject: BUG #18313: No error triggered when subtracting an interval from a timestamp