Multiple Foreign Keys - Mailing list pgsql-general

From Jason Burke
Subject Multiple Foreign Keys
Date
Msg-id 3A155275.BDE0662F@saintjoe.edu
Whole thread Raw
List pgsql-general
I was wondering if there is any way to set up a foreign key that is
valid not just if the value exists in one table but if it exists in any
of 3 tables.  Here is what I mean.  I have a sequence called 'id_number'
that I start at 1 and increment by 1 every time its used.  I then have 3
tables each of which has an id attribute the is set up like this:

id int PRIMARY KEY default nextval('id_number'),

My question is this.  I have a fourth table that also has an id field
but I want to constrain it so that it must be a valid id from either
table 1, or table 2, or table 3.  I cannot seem to set it up except for
making it be in all 3 which obviously could never happen.  I'd
appreciate any advice you could provide me in this regard.  Maybe it's
not possible, but if there is a way it would sure save a lot of hassle
in otherwise having to redesign the DB.

Thanks

jason j burke

pgsql-general by date:

Previous
From: "Adam Lang"
Date:
Subject: Re: What language
Next
From: Alfred Perlstein
Date:
Subject: Re: What language