pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John McCawley <nospam@hardgeus.com>
To: Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
Cc: Pgsql-sql@postgresql.org <Pgsql-sql@postgresql.org>
Subject: Re: Foreign key to 2 tables problem
Date: Tue, 22 Nov 2005 09:37:33 -0600
Message-ID: <43833B3D.2020407@hardgeus.com> (raw)
In-Reply-To: <1132673053.5701.9.camel@Panoramix>
References: <1132673053.5701.9.camel@Panoramix>

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



view thread (6+ messages)  latest in thread

Message-ID: <43833B3D.2020407@hardgeus.com>
Permalink:  ../43833B3D.2020407@hardgeus.com/
Also on:    postgresql.org/message-id/43833B3D.2020407@hardgeus.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: nospam@hardgeus.com, J.Kraaijeveld@Askesis.nl
  Subject: Re: Foreign key to 2 tables problem
  In-Reply-To: <43833B3D.2020407@hardgeus.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox