Re: foreign key restrictions - Mailing list pgsql-general

From Gregory Stark
Subject Re: foreign key restrictions
Date
Msg-id 87prohc4xh.fsf@oxford.xeocode.com
Whole thread Raw
In response to Re: foreign key restrictions  ("Richard Broersma" <richard.broersma@gmail.com>)
Responses Re: foreign key restrictions  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
"Richard Broersma" <richard.broersma@gmail.com> writes:

> On Sun, Aug 10, 2008 at 1:15 AM,  <rafal@zorro.isa-geek.com> wrote:
>
>> Since table TWO has a unique constraint on column ID, the (ID, OFONE) pair
>> will also be unique, obviously.
>
> This statement is not completely true.  The only part of the pair that
> is true is ID.  Also there is not unique constraint on the pare.  So
> there is no way to PG to build a foreing key on the pair.

Uhm, afaics he's right. if ID is unique not null then <ID, OFONE> also has to
be unique. That is, there could be duplicate values of OFONE but they'll all
have different values of ID anyways.

I'm not sure if there's a fundamental reason why there has to be an index that
exactly matches the foreign key or not -- offhand I can't think of one.

--
  Gregory Stark
  EnterpriseDB          http://www.enterprisedb.com
  Get trained by Bruce Momjian - ask me about EnterpriseDB's PostgreSQL training!

pgsql-general by date:

Previous
From: "Richard Broersma"
Date:
Subject: Re: foreign key restrictions
Next
From: Martijn van Oosterhout
Date:
Subject: Re: foreign key restrictions