X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6AE535E46E9 for ; Wed, 18 Aug 2004 14:45:33 -0300 (ADT) 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 78767-06 for ; Wed, 18 Aug 2004 17:45:38 +0000 (GMT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 0EB6F5E46DF for ; Wed, 18 Aug 2004 14:45:29 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id 17F64356A2; Wed, 18 Aug 2004 10:45:35 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id 1595A356A0; Wed, 18 Aug 2004 10:45:35 -0700 (PDT) Date: Wed, 18 Aug 2004 10:45:35 -0700 (PDT) From: Stephan Szabo To: Josh Berkus Cc: Jan Wieck , Markus Bertheau , olly@lfix.co.uk, pgsql-sql@postgresql.org Subject: Re: multi column foreign key for implicitly unique columns In-Reply-To: <200408181005.13230.josh@agliodbs.com> Message-ID: <20040818104151.Y6662@megazone.bigpanda.com> References: <1092734724.2627.4.camel@dicaprio.akademie1.de> <200408171945.15663.josh@agliodbs.com> <41235A90.1080300@Yahoo.com> <200408181005.13230.josh@agliodbs.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/207 X-Sequence-Number: 18704 On Wed, 18 Aug 2004, Josh Berkus wrote: > > In the case that a table constraint is a referential constraint, > > the table is referred to as the referencing table. The referenced > > columns of a referential constraint shall be the unique columns of > > some unique constraint of the referenced table. > > Missed that one. Interesting. AFAIK, the uniqueness of referenced columns is > NOT a requirement of Relaitonal Algebra. So why does SQL require it? > > Maybe I'll ask Joe Celko after he finishes moving to Austin. > > I have my own issue that forced me to use triggers. Given: > > table users ( > name > login PK > status > etc. ) > > table status ( > status > relation > label > definition > PK status, relation ) > > the relationship is: > users.status = status.status AND status.relation = 'users'; > > This is a mathematically definable constraint, but there is no way in standard > SQL to create an FK for it. This is one of the places I point to whenever > we have the "SQL is imperfectly relational" discussion. Well, I think SQL does give a way of specifying that constraint through assertions and check constraints with subselects. We just don't support either of those constructs.