Re: foreign key restrictions - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: foreign key restrictions
Date
Msg-id 20080810143936.GA13014@svana.org
Whole thread Raw
In response to Re: foreign key restrictions  ("Richard Broersma" <richard.broersma@gmail.com>)
List pgsql-general
On Sun, Aug 10, 2008 at 07:10:10AM -0700, Richard Broersma wrote:
> On Sun, Aug 10, 2008 at 1:15 AM,  <rafal@zorro.isa-geek.com> wrote:
>
> > CREATE TABLE two (id int not null unique, ofone int references one(id),
> > CREATE TABLE three(one int not null, two int, info text, foreign key (one,
> > two) references two (one, id));
> >
> > 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.

Eh? If ID is unique, then (ID,OFONE) is also unique. You don't need to
add another unique constraint because they're already guarenteed to be
unique.

While I admit the table structure is a bit odd, it should be fairly
easy to support it in postgres.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

Attachment

pgsql-general by date:

Previous
From: Gregory Stark
Date:
Subject: Re: foreign key restrictions
Next
From: Tom Lane
Date:
Subject: Re: foreign key restrictions