Re: Foreign key to 2 tables problem - Mailing list pgsql-sql

From John McCawley
Subject Re: Foreign key to 2 tables problem
Date
Msg-id 43833B3D.2020407@hardgeus.com
Whole thread Raw
In response to Foreign key to 2 tables problem  (Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>)
Responses Re: Foreign key to 2 tables problem
List pgsql-sql
I've never seen anything like that.  I'm sure it's conceivable that you 
could write a weird trigger for it, but you have to consider 
maintainability, and what your queries are going to look like.  I 
haven't seen your datamodel, but it would seem that you could accomplish 
what you're looking for by having two separate foriegn key columns in 
the bankaccount table, one for the customer and one for the supplier.  
While your queries may end up somewhat funky, I can't imagine they'd be 
any worse than what would occur with what you're suggesting.

However, if customers or suppliers can have multiple accounts, you are 
going to need an intermediate table, as suggested by Neil.


Joost Kraaijeveld wrote:

>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?
>
>
>TIA
>
>  
>


pgsql-sql by date:

Previous
From: Achilleus Mantzios
Date:
Subject: Re: Foreign key to 2 tables problem
Next
From: Rod Taylor
Date:
Subject: Re: Foreign key to 2 tables problem