Re: Foreign key to 2 tables problem

From: Achilleus Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
To: Joost Kraaijeveld <J(dot)Kraaijeveld(at)Askesis(dot)nl>
Cc: "Pgsql-sql(at)postgresql(dot)org" <Pgsql-sql(at)postgresql(dot)org>
Subject: Re: Foreign key to 2 tables problem
Date: 2005-11-22 16:32:39
Message-ID: Pine.LNX.4.44.0511221827300.24697-100000@matrix.gatewaynet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

O Joost Kraaijeveld έγραψε στις Nov 22, 2005 :

> Hi,
>
> Is there a way to create a foreign key to 2 tables: e.g. a bankaccount
> table that has a column "owner", that must point to a record in either
> the customer or the supplier table?

While there are techniques to accomplish this,
i see a problem:
How do you know if a certain value in owner is to be joined
with e.g. customer and not supplier??

The right way is to have 2 columns that can be null,
pointing to customer,supplier respectively,
and then write a trigger to ensure that exactly one
is not null.

>
>
> TIA
>
>

--
-Achilleus

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Achilleus Mantzios 2005-11-22 17:07:30 Re: Triggers
Previous Message John McCawley 2005-11-22 16:27:23 Re: deferrable on unique