Re: Setting a FK to look at only selected rows in the 'look-up' table... - Mailing list pgsql-novice

From Tom Lane
Subject Re: Setting a FK to look at only selected rows in the 'look-up' table...
Date
Msg-id 27717.1198897902@sss.pgh.pa.us
Whole thread Raw
In response to Re: Setting a FK to look at only selected rows in the 'look-up' table...  ("Sean Davis" <sdavis2@mail.nih.gov>)
Responses Re: Setting a FK to look at only selected rows in the 'look-up' table...  ("Sean Davis" <sdavis2@mail.nih.gov>)
List pgsql-novice
"Sean Davis" <sdavis2@mail.nih.gov> writes:
> On Dec 28, 2007 7:01 PM, Greg Cocks <gcocks@stoller.com> wrote:
>> I would like to restrict the foreign key for d_borehole.depth_unit to be
>> only those values in r_unit.unit_id where r_unit.unit_length = 'length' (
>> i.e., so that only applicable 'length' units can be utilized for the
>> depths (feet, metres, inches, etc))

> This cannot be done with foreign keys I don't think.

Maybe I missed something, but couldn't a two-column foreign key
constraint on (value, unit) be made to serve the purpose?

            regards, tom lane

pgsql-novice by date:

Previous
From: "Sean Davis"
Date:
Subject: Re: Setting a FK to look at only selected rows in the 'look-up' table...
Next
From: "Sean Davis"
Date:
Subject: Re: Setting a FK to look at only selected rows in the 'look-up' table...