X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 60D05475EC9 for ; Mon, 7 Apr 2003 17:41:28 -0400 (EDT) Received: from europa.janwieck.net (h00045a2e4e7c.ne.client2.attbi.com [24.131.181.55]) by postgresql.org (Postfix) with ESMTP id A59DA4758E6 for ; Mon, 7 Apr 2003 17:41:27 -0400 (EDT) Received: from Yahoo.com (linksys.janwieck.net [192.168.192.1]) (authenticated) by europa.janwieck.net (8.11.6/8.11.6) with ESMTP id h37LfNa17346; Mon, 7 Apr 2003 17:41:23 -0400 Message-ID: <3E91F06C.2435AD35@Yahoo.com> Date: Mon, 07 Apr 2003 17:41:00 -0400 From: Jan Wieck Organization: Home X-Mailer: Mozilla 4.8 [en] (Windows NT 5.0; U) X-Accept-Language: en,ru MIME-Version: 1.0 To: Rod Taylor Cc: Saad Saeed , pgsql-sql@postgresql.org Subject: Re: Creating a foreign key on the Union of two tables References: <1049734135.40144.17.camel@jester> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-28.5 required=5.0 tests=BAYES_10,EMAIL_ATTRIBUTION,QUOTED_EMAIL_TEXT,REFERENCES, REPLY_WITH_QUOTES autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/103 X-Sequence-Number: 12804 Rod Taylor wrote: > > On Sun, 2003-04-06 at 17:53, Saad Saeed wrote: > > I have 2 tables "A" and "B" in mySQL. They both have an attribute 'id' > > which is unique between the 2 tables. I want the union of these 2 > > attributes to be a foreign key in a 3rd table "C". How do I specify > > this constraing in sql (mySQL) in table C? And for complex reasons I > > cannot merge the 2 tables A and B. > > Can't say for MySQL (since this is a PostgreSQL list!!!!!), but creating > a foreign key like that to 2 different tables is against spec because > one cannot create a unique constraint across 2 tables. > > That said, you could create a set of pl/pgsql functions that can imitate > what a foreign key does and will work in the situation you describe -- > if you're using PostgreSQL. Or seeting up table D plus custom triggers on A and B so that D contains the union of both. That would result in a virtual unique constraint over A and B together since the foreign key constraint now against D requires it's id column to be unique. Without more background on the purpose or the underlying business process it's hard though to tell what's best. Jan -- #======================================================================# # It's easier to get forgiveness for being wrong than for being right. # # Let's break this rule - forgive me. # #================================================== JanWieck@Yahoo.com #