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 A7D995E37CE for ; Tue, 17 Aug 2004 11:46:41 -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 06890-02 for ; Tue, 17 Aug 2004 14:46:42 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 45CED5E37CB for ; Tue, 17 Aug 2004 11:46:38 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i7HEkZRB004308; Tue, 17 Aug 2004 10:46:37 -0400 (EDT) To: Stephan Szabo Cc: Richard Huxton , Markus Bertheau , pgsql-sql@postgresql.org Subject: Re: multi column foreign key for implicitly unique columns In-reply-to: <20040817072443.S60684@megazone.bigpanda.com> References: <1092734724.2627.4.camel@dicaprio.akademie1.de> <4121D55D.1040105@archonet.com> <20040817072443.S60684@megazone.bigpanda.com> Comments: In-reply-to Stephan Szabo message dated "Tue, 17 Aug 2004 07:26:56 -0700" Date: Tue, 17 Aug 2004 10:46:35 -0400 Message-ID: <4307.1092753995@sss.pgh.pa.us> From: Tom Lane 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/168 X-Sequence-Number: 18665 Stephan Szabo writes: > No, actually, it's that the SQL92 (at least) spec says explicitly that > there must be a unique constraint across all of the columns specified, not > merely across a subset. > "then the set of column names of that shall be > equal to the set of column names in the unique columns of a unique > constraint of the referenced table." SQL99 says the same. 11.8 syntax rule 3a: a) If the specifies a , then the set of s contained in that shall be equal to the set of s contained in the of a unique constraint of the referenced table. I think one reason for this is that otherwise it's not clear which unique constraint the FK constraint depends on. Consider create table a (f1 int unique, f2 int unique); create table b (f1 int, f2 int, foreign key (f1,f2) references a(f1,f2)); How would you decide which constraint to make the FK depend on? It'd be purely arbitrary. regards, tom lane