Re: 1 foreign key to 2 different tables?

From: Jean-Luc Lachance <jllachan(at)sympatico(dot)ca>
To: rkr(at)buildways(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: 1 foreign key to 2 different tables?
Date: 2004-05-01 19:29:15
Message-ID: 4093FA8B.7090804@sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Use CHECK when you create the table.

Ryan Riehle wrote:

> Hi,
>
> I have a key structure like so:
>
> a c b
> +----------+ +---------+ +----------+
> | PriKey1 |--->| ForKey |<---| PriKey2 |
> | | | Flag | | |
> +----------+ +---------+ +----------+
>
> ...where c.ForKey is a value from PriKey1 OR PriKey2, which are different
> values. All fields have the same data type; a.PriKey1 and b.PriKey2 are
> sequences. How does one enfore referential integrity in this structure so
> that c.ForKey references a.PriKeya when Flag is True or references b.PriKey2
> when Flag is False? Looked pretty hard through the lists and on Google last
> night with no luck :(
>
> -Ryan Riehle
> http://www.buildways.com
>
> KEYWORDS: one foreign key, multiple primary keys, multiple tables,
> generalization, superclass, subclass, constraint
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2004-05-01 20:17:46 Re: 1 foreign key to 2 different tables?
Previous Message Alvaro Herrera 2004-05-01 19:13:40 postgresql.org relay failing?