Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Te18j-0004kS-Ia for pgsql-sql@arkaria.postgresql.org; Thu, 29 Nov 2012 10:14:41 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Te18i-00013h-ND for pgsql-sql@arkaria.postgresql.org; Thu, 29 Nov 2012 10:14:40 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Te18h-00013b-Mj for pgsql-sql@postgresql.org; Thu, 29 Nov 2012 10:14:39 +0000 Received: from hub.ringways.co.uk ([77.86.27.30] helo=mail.ringways.co.uk) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Te18f-0004fi-PG for pgsql-sql@postgresql.org; Thu, 29 Nov 2012 10:14:39 +0000 Received: from localhost ([127.0.0.1] helo=mail.ringways.co.uk) by mail.ringways.co.uk with esmtp (Exim 4.69) (envelope-from ) id 1Te18Z-0001Kf-L0 for pgsql-sql@postgresql.org; Thu, 29 Nov 2012 10:14:33 +0000 Received: from eddie.ringways.co.uk ([10.1.1.115] helo=eddie.ringways.co.uk) by mail.ringways.co.uk with ESMTP id qAEQA8Nb74275; Thu, 29 Nov 2012 10:14:26 +0000 From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: unique keys / foreign keys on two tables Date: Thu, 29 Nov 2012 10:14:27 +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: <201211291014.27989.gary.stainburn@ringways.co.uk> X-SpamTest-Envelope-From: gary.stainburn@ringways.co.uk X-SpamTest-Info: Profiles 20401 [Mar 31 2011] X-SpamTest-Method: none X-SpamTest-Rate: 0 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0285], KAS30/SDK/Release X-Anti-Virus: Kaspersky Mail Gateway, version: 5.6.28/RELEASE, bases: 20110331T110535 #5151353, check: 20121129 clean X-Spam-Score: -51.6 (---------------------------------------------------) X-Spam-Report: Spam detection software, running on the system "ollie.ringways.co.uk", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see Gary Stainburn for details. Content preview: I'm designing the schema to store a config from our switchboards. As with all PBX's the key is the dialed number which is either an extension number or a group (hunt/ring/pickup) number. I have two tables, one for extensions and one for groups, basically [...] Content analysis details: (-51.6 points, 15.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -50 ALL_TRUSTED Passed through trusted hosts only via SMTP -2.6 BAYES_00 BODY: Bayesian spam probability is 0 to 1% [score: 0.0000] 1.0 RING_SAFE RING_SAFE X-Pg-Spam-Score: -0.4 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org I'm designing the schema to store a config from our switchboards. As with all PBX's the key is the dialed number which is either an extension number or a group (hunt/ring/pickup) number. I have two tables, one for extensions and one for groups, basically ext_id int4 primary key ext_desc text .... .... .... and grp_id int4 primary key grp_desc text ..... ..... ..... I now need to be able to ensure the id field is unique across both tables. Presumably I can do this with a function and a constraint for each table. Does anyone have examples of this? Next I have other tables that refer to *destinations* which will be an ID that could be either an extension or a group. Examples are 'Direct Dial In' numbers which could point to either. How would I do that? -- Gary Stainburn Group I.T. Manager Ringways Garages http://www.ringways.co.uk -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql