Re: FK v.s unique indexes

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Rafal Pietrak <rafal(at)ztk-rp(dot)eu>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: FK v.s unique indexes
Date: 2018-07-03 22:55:37
Message-ID: CAKFQuwZLmmG5p-DDBPu6oeLe2UkbRNps4HKPv3Bc8Moo-Gh16w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tuesday, July 3, 2018, Rafal Pietrak <rafal(at)ztk-rp(dot)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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Igor Korot 2018-07-03 23:42:57 Re: How to watch for schema changes
Previous Message Tim Cross 2018-07-03 22:13:28 Re: FK v.s unique indexes