Foreign key with check?

From: Jeff Boes <jeff(at)endpoint(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Foreign key with check?
Date: 2005-07-27 20:08:19
Message-ID: 42E7E9B3.4080500@endpoint.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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).

I think I have to do this with an additional trigger. Any other options?

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2005-07-27 20:37:59 Re: Foreign key with check?
Previous Message Chris Browne 2005-07-27 15:31:00 Re: REINDEX DATABASE