Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id A39C81337B69 for ; Wed, 5 Jan 2011 06:40:18 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 42791-06 for ; Wed, 5 Jan 2011 10:40:11 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.ringways.co.uk (hub.ringways.co.uk [77.86.27.30]) by mail.postgresql.org (Postfix) with ESMTP id 328AD1337B68 for ; Wed, 5 Jan 2011 06:40:10 -0400 (AST) Received: from eddie.ringways.co.uk ([10.1.1.115]) by mail.ringways.co.uk with esmtp (Exim 4.69) (envelope-from ) id 1PaQmk-0003te-4A for pgsql-sql@postgresql.org; Wed, 05 Jan 2011 10:40:07 +0000 From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: Re: foreign key question Date: Wed, 5 Jan 2011 10:40:08 +0000 User-Agent: KMail/1.9.10 References: <201101050953.43830.gary.stainburn@ringways.co.uk> In-Reply-To: <201101050953.43830.gary.stainburn@ringways.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201101051040.08575.gary.stainburn@ringways.co.uk> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201101/6 X-Sequence-Number: 34953 On Wednesday 05 January 2011 09:53:43 Gary Stainburn wrote: > Now I want to set up a new access level table specific to the itinerary, > along the lines of > > u_id int4 not null references users(u_id) > fl_level int4 not null references facility_levels(16, fl_level) > > Firstly, is this possible, and secondly how would I do it? I've managed a work-around by creating a column that defaults to 16 and then used ALTER TABLE ADD CONSTRAINT to add a foreign key with two pairs of keys. This feels wrong though as my table now has a column that is ultimately redundant, and worse can be changed to a wrong value. Ok, I've sorted the last bit by adding a check constraint to make sure it always contains 16, but it still feels wrong. -- Gary Stainburn I.T. Manager Ringways Garages http://www.ringways.co.uk