Skip site navigation (1) Skip section navigation (2)

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

From: "Sean Davis" <sdavis2(at)mail(dot)nih(dot)gov>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Greg Cocks" <gcocks(at)stoller(dot)com>, "PostgreSQL List - Novice" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Setting a FK to look at only selected rows in the 'look-up' table...
Date: 2007-12-29 03:28:39
Message-ID: 264855a00712281928t100fd3c5wee491a09561a3507@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On Dec 28, 2007 10:11 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> "Sean Davis" <sdavis2(at)mail(dot)nih(dot)gov> writes:
> > On Dec 28, 2007 7:01 PM, Greg Cocks <gcocks(at)stoller(dot)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?
>

Yep.  If he modifies his schema somewhat to include the extra column in the
first table.

Sean

In response to

Responses

pgsql-novice by date

Next:From: Brian HurtDate: 2008-01-02 17:32:51
Subject: Combined PITR/pg_dump backups?
Previous:From: Tom LaneDate: 2007-12-29 03:11:42
Subject: Re: Setting a FK to look at only selected rows in the 'look-up' table...

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group