Re: FK v.s unique indexes - Mailing list pgsql-general

From David G. Johnston
Subject Re: FK v.s unique indexes
Date
Msg-id CAKFQuwZLmmG5p-DDBPu6oeLe2UkbRNps4HKPv3Bc8Moo-Gh16w@mail.gmail.com
Whole thread Raw
In response to FK v.s unique indexes  (Rafal Pietrak <rafal@ztk-rp.eu>)
Responses Re: FK v.s unique indexes  (Rafal Pietrak <rafal@ztk-rp.eu>)
List pgsql-general
On Tuesday, July 3, 2018, Rafal Pietrak <rafal@ztk-rp.eu> wrote:

ERROR:  there is no unique constraint matching given keys for referenced
table "test2"
----------------------------

I cannot see any reasons why this functionality is blocked.

In particular, contrary to what the ERROR says, the target table *does
have* a "unique constraint matching given keys", admittedly only
partial.

You are making the common error of confusing the distinct concepts of constraints and indexs.  Table constraints cannot be partial by definition, and are a logical concept constraining the data model.  Indexes are physical objects that only aid in the execution of queries.  The only crossover is that the implementation of a unique table constraint uses a full unique index as an implementation detail.

The error says 'constraint' and indeed you have nit defined a relevant constraint in your schema, just indexes.

David J.

pgsql-general by date:

Previous
From: Tim Cross
Date:
Subject: Re: FK v.s unique indexes
Next
From: Igor Korot
Date:
Subject: Re: How to watch for schema changes