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 67DBBDAFA6 for ; Tue, 22 Nov 2005 11:35:18 -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 63974-07 for ; Tue, 22 Nov 2005 15:35:22 +0000 (GMT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from matrix.gatewaynet.com (host2.dynacom.ondsl.gr [62.103.35.210]) by svr1.postgresql.org (Postfix) with ESMTP id 1BD26DAFF1 for ; Tue, 22 Nov 2005 11:35:14 -0400 (AST) Received: from matrix.gatewaynet.com (localhost.localdomain [127.0.0.1]) by matrix.gatewaynet.com (8.12.8/8.12.8) with ESMTP id jAMGWdKc024851; Tue, 22 Nov 2005 18:32:39 +0200 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.8/8.12.8/Submit) with ESMTP id jAMGWdVh024847; Tue, 22 Nov 2005 18:32:39 +0200 Date: Tue, 22 Nov 2005 18:32:39 +0200 (EET) From: Achilleus Mantzios To: Joost Kraaijeveld cc: "Pgsql-sql@postgresql.org" Subject: Re: Foreign key to 2 tables problem In-Reply-To: <1132673053.5701.9.camel@Panoramix> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-7 Content-Transfer-Encoding: 8BIT X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200511/196 X-Sequence-Number: 23447 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