X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 32FE9D86C2 for ; Tue, 22 Nov 2005 11:37:37 -0400 (AST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64124-06 for ; Tue, 22 Nov 2005 15:37:39 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from worleyco.com (unknown [70.158.54.226]) by svr1.postgresql.org (Postfix) with ESMTP id 2D217DB022 for ; Tue, 22 Nov 2005 11:37:32 -0400 (AST) Received: from [192.168.4.32] (unknown [192.168.4.32]) by worleyco.com (Postfix) with ESMTP id 535CD133B3B; Tue, 22 Nov 2005 09:37:38 -0600 (CST) Message-ID: <43833B3D.2020407@hardgeus.com> Date: Tue, 22 Nov 2005 09:37:33 -0600 From: John McCawley User-Agent: Mozilla Thunderbird 1.0.6 (X11/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Joost Kraaijeveld Cc: "Pgsql-sql@postgresql.org" Subject: Re: Foreign key to 2 tables problem References: <1132673053.5701.9.camel@Panoramix> In-Reply-To: <1132673053.5701.9.camel@Panoramix> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[AWL=0.000] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200511/197 X-Sequence-Number: 23448 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 > > >