pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: gparc@online.fr
Subject: BUG #18295: In PostgreSQL a unique index on targeted columns is sufficient to support a foreign key
Date: Mon, 15 Jan 2024 11:37:19 +0000
Message-ID: <18295-0ed0fac5c9f7b17b@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      18295
Logged by:          Gilles PARC
Email address:      gparc@online.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.



view thread (15+ messages)  latest in thread

Message-ID: <18295-0ed0fac5c9f7b17b@postgresql.org>
Permalink:  ../18295-0ed0fac5c9f7b17b@postgresql.org/
Also on:    postgresql.org/message-id/18295-0ed0fac5c9f7b17b@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, gparc@online.fr
  Subject: Re: BUG #18295: In PostgreSQL a unique index on targeted columns is sufficient to support a foreign key
  In-Reply-To: <18295-0ed0fac5c9f7b17b@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox