From: Bruno Wolff III <bruno@wolff.to>
To: Jeff Boes <jeff@endpoint.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Foreign key with check?
Date: Wed, 27 Jul 2005 15:37:59 -0500
Message-ID: <20050727203759.GA3884@wolff.to> (raw)
In-Reply-To: <42E7E9B3.4080500@endpoint.com>
References: <42E7E9B3.4080500@endpoint.com>
On Wed, Jul 27, 2005 at 16:08:19 -0400,
Jeff Boes <jeff@endpoint.com> wrote:
> Given a table like this:
>
> create table primary (
> a integer primary key,
> b boolean
> );
>
> And another like this:
>
> create table secondary (
> a integer,
> some_other_fields
> );
>
>
> I would like a foreign key constraint on the "secondary" table that
> looks something like:
>
> foreign key (a, true) references primary (a, b)
>
> That is, a row in "secondary" is allowed to reference a row in "primary"
> if and only if that referenced row has (b = true).
If what you are saying is that all entries in secondary need to reference
a row in primary and in addition the referenced row must have b true, then
you can do this fairly simply using a bit of extra space.
Add a row b to secondary with a constraint that b = true. Then make the
foreign key reference on both a and b.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: bruno@wolff.to, jeff@endpoint.com
Subject: Re: Foreign key with check?
In-Reply-To: <20050727203759.GA3884@wolff.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox