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 7D3F95E46C4 for ; Wed, 18 Aug 2004 16:16:12 -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 14651-08 for ; Wed, 18 Aug 2004 19:16:17 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 8DA8E5E4249 for ; Wed, 18 Aug 2004 16:16:07 -0300 (ADT) Received: (qmail 23550 invoked by uid 500); 18 Aug 2004 19:24:40 -0000 Date: Wed, 18 Aug 2004 14:24:40 -0500 From: Bruno Wolff III 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 Message-ID: <20040818192440.GB21979@wolff.to> Mail-Followup-To: Josh Berkus , Jan Wieck , Markus Bertheau , olly@lfix.co.uk, pgsql-sql@postgresql.org 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 Content-Disposition: inline In-Reply-To: <200408181005.13230.josh@agliodbs.com> User-Agent: Mutt/1.5.6i 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/213 X-Sequence-Number: 18710 On Wed, Aug 18, 2004 at 10:05:13 -0700, Josh Berkus wrote: > > 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. If users is supposed to reference status you can do this by adding a relation column to users, using a constraint to force relation to always be 'users' and then having (status, relation) being a foreign key.