Search Postgresql Archives

Re: foreign key restrictions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Aug 10, 2008 at 07:10:10AM -0700, Richard Broersma wrote:
> On Sun, Aug 10, 2008 at 1:15 AM,  <rafal@xxxxxxxxxxxxxxxxxx> 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@xxxxxxxxx>   http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while 
> boarding. Thank you for flying nlogn airlines.

Attachment: signature.asc
Description: Digital signature


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux