Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 4E1DC1337B5C for ; Wed, 5 Jan 2011 05:53:56 -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 24178-07 for ; Wed, 5 Jan 2011 09:53:48 +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 BF0E61337B2F for ; Wed, 5 Jan 2011 05:53:47 -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 1PaQ3p-00037z-FQ for pgsql-sql@postgresql.org; Wed, 05 Jan 2011 09:53:42 +0000 From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: foreign key question Date: Wed, 5 Jan 2011 09:53:43 +0000 User-Agent: KMail/1.9.10 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201101050953.43830.gary.stainburn@ringways.co.uk> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.51 tagged_above=-5 required=5 tests=BAYES_05=-0.5, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201101/5 X-Sequence-Number: 34952 Hi folks, I have a table which lists facilities and another table that lists access levels for those facilities. All straight forward using a foreign key set up using a normal references clause. users=# select f_id, f_desc from facilities order by f_id; f_id | f_desc ------+--------------------- 1 | Login 3 | Users .... 16 | Itinerary .... 31 rows) users=# select * from facility_levels ; fl_f_id | fl_level | fl_desc ---------+----------+----------------------- 16 | 1 | Own itinerary 16 | 2 | Dealer/Dept itinerary 16 | 3 | Dept itinerary 16 | 4 | Dealer/Dept On/Off 16 | 5 | Dept On/Off 16 | 6 | All On/Off 16 | 7 | All features (7 rows) users=# 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? -- Gary Stainburn I.T. Manager Ringways Garages http://www.ringways.co.uk