Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 5D847475974 for ; Wed, 28 Aug 2002 09:36:45 -0400 (EDT) Received: from jalapeno.crazydogs.org (unknown [212.78.70.100]) by postgresql.org (Postfix) with ESMTP id BEF8F475843 for ; Wed, 28 Aug 2002 09:36:44 -0400 (EDT) Received: from rp by jalapeno.crazydogs.org with local (Exim 3.35 #1 (Debian)) id 17k304-00067F-00 for ; Wed, 28 Aug 2002 14:36:48 +0100 Date: Wed, 28 Aug 2002 14:36:48 +0100 From: Richard Poole To: pgsql-admin@postgresql.org Subject: Re: Multiple keys? Message-ID: <20020828133648.GA18842@guests.deus.net> References: <200208280210.44746.cshobe@secureworks.net> <20020828102247.GA23727@guests.deus.net> <200208280634.55534.cshobe@secureworks.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200208280634.55534.cshobe@secureworks.net> User-Agent: Mutt/1.3.28i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/320 X-Sequence-Number: 5434 On Wed, Aug 28, 2002 at 06:34:55AM -0400, Casey Allen Shobe wrote: > On Wednesday 28 August 2002 06:22 am, Richard Poole wrote: > > Your two-column constraint, the one you need to add to get your foreign > > key working, implies your three-column one. So you can just get rid of > > the three-column one. > > Hmm, that's a problem :\. See I want the table to be constrained by a unique > combination of the three, but I want the second table to be constrained by a > unique combination of only the two, as the third column is not present in the > second table. > > I'm uncertain what to do, but I thank you for pointing out my error in > overconstraining the first table. You could do it with one more table, perhaps? CREATE TABLE package_versions ( package_id integer NOT NULL REFERENCES packages, package_version varchar(16) NOT NULL DEFAULT '0.0.1', UNIQUE(package_id, package_version) ); CREATE TABLE package_info ( package_id integer NOT NULL, package_version varchar(16) NOT NULL, info_type varchar(32) NOT NULL DEFAULT 'extra_data', -- other fields FOREIGN KEY (package_id, package_version) REFERENCES package_versions, UNIQUE (package_id, package_version, info_type) ); CREATE TABLE box_packages ( package_id integer NOT NULL, package_version varchar(16) NOT NULL, -- other fields FOREIGN KEY (package_id, package_version) REFERENCES package_versions, -- other constraints ); Does that do what you need? Richard