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

1 foreign key to 2 different tables?

From: "Ryan Riehle" <rkr(at)buildways(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: 1 foreign key to 2 different tables?
Date: 2004-05-01 18:51:14
Message-ID: 000001c42fad$5350abe0$0302a8c0@buildways (view raw, whole thread or download thread mbox)
Thread:
Lists: pgsql-general
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


In response to

Responses

pgsql-general by date

Next:From: Mike NolanDate: 2004-05-01 19:00:34
Subject: Re: users rights per table
Previous:From: victorDate: 2004-05-01 18:05:53
Subject: users rights per table

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