From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
---|---|
To: | Richard Broersma <richard(dot)broersma(at)gmail(dot)com> |
Cc: | rafal(at)zorro(dot)isa-geek(dot)com, pgsql general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: foreign key restrictions |
Date: | 2008-08-10 14:39:36 |
Message-ID: | 20080810143936.GA13014@svana.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(at)zorro(dot)isa-geek(dot)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(at)svana(dot)org> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2008-08-10 16:23:39 | Re: foreign key restrictions |
Previous Message | Gregory Stark | 2008-08-10 14:36:58 | Re: foreign key restrictions |