Re: FK v.s unique indexes

From: Rob Sargent <robjsargent(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-05 08:11:51
Message-ID: 3F47B63F-E3CE-4FF7-9632-D0B9C7FF75C3@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On Jul 5, 2018, at 1:30 AM, Rafal Pietrak <rafal(at)ztk-rp(dot)eu> wrote:
>
>
>
> W dniu 04.07.2018 o 00:55, David G. Johnston pisze:
>> On Tuesday, July 3, 2018, Rafal Pietrak <rafal(at)ztk-rp(dot)eu
>> <mailto: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.
>
> Hmmm..
>
> This does not match "my reality". Naturally I may be wrong, but the
> example I've posted reflects my actual data I'm putting into the RDBMS.
> That is:
> 1. the data has unique constraint on (load,a,b,c)
> 2. and the data have additional unique constraints on (load,a), provided
> c is true, and (load,b) whenever c is false.
>
> Pls consider in real life: load (a person), can have either a (a kind of
> brest cancer); or b (a kind of prostrate) - this is only a cooked
> example attemping to illustrate, that one may need to put additional
> constraints on the entire dataset.
>

It’s difficult enough to define a unique person (without mother and father) and certainly this weeks definition of burden is not likely to help matters. If you’re main worry is data consistency you might be better off normalizing your structure - either with separate tables per cancer type (person id, cancer specifics; unique on person) or in a single table one per line (person id, cancer type, cancer description; unique on person). You can reconstitue person,breast,prostate from either of those. We won’t quibble on one person having both (though remotely possible, men do get breast cancer).

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message pinker 2018-07-05 08:54:33 Re: FK v.s unique indexes
Previous Message Rafal Pietrak 2018-07-05 07:32:56 Re: FK v.s unique indexes