Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 660F09FB7A2 for ; Tue, 27 Mar 2007 10:22:03 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 85199-02-5 for ; Tue, 27 Mar 2007 10:21:40 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.238]) by postgresql.org (Postfix) with ESMTP id 249839FB46C for ; Tue, 27 Mar 2007 10:21:46 -0300 (ADT) Received: by wr-out-0506.google.com with SMTP id 70so1161508wra for ; Tue, 27 Mar 2007 06:21:45 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=gdIvZ/v6zKGXiKbHKXmoUCOg95HVcPjbYIp8Urk7HbNm1JkJ3QjwZWcJMnMjcR3mDxfVtbq0PxPZD/oazYXcyHCOvjV+mIoDrO8M1x7WRnrUZubN+iLBY/b0kFAncxzlBeD7idJM/Dwc/3pBUDyHRtx+TKThnyaZaXyPUkqLmWU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=i99R9fmArjuuLUUqe8A4Dp2qyfoZ2hF7E8WI6UYRFSzfiBH5de+/FLJ7ZtCqsZPQy1OoJFBOQgA/0GAO/oFwqff8fycQfqE52XCTTcG1ZC4IDUatHK7ZvbN6+5RoToMv9BJsZaUk0UbxXM6SL35KxxKpShb5wdOxGDyFDyAeYG0= Received: by 10.114.152.17 with SMTP id z17mr3161734wad.1175001704451; Tue, 27 Mar 2007 06:21:44 -0700 (PDT) Received: by 10.114.47.8 with HTTP; Tue, 27 Mar 2007 06:21:44 -0700 (PDT) Message-ID: <4f4c2a010703270621h5137a4e5rb515a9be9034a543@mail.gmail.com> Date: Tue, 27 Mar 2007 09:21:44 -0400 From: "Jon Horsman" To: pgsql-sql@postgresql.org Subject: Foreign Unique Constraint MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/312 X-Sequence-Number: 27950 I was wondering if someone could help point me in the right direction w.r.t. foreign unique constraints. I'm working on a legacy database and have a new requirement and am not sure how to do it. I have something like this create table table1 ( id SERIAL PRIMARY KEY extension UNIQUE, ) create table table2 ( id SERIAL PRIMARY KEY extension UNIQUE, ) Basically table 1 and table 2 both have the concept of an extension that must be unique but the rest of the info in the tables are different. I need to ensure that if i add an entry to table 1 with extension 1000 that it will fail if there is already an entry in table2 with the same extension. Essentially i need to do something like the following but i get errors saying this can't be done. alter table table1 add check (extension <> table2.extension); It should be noted i am using pg version 7.4.13 and this can't change. Thanks for any help you can offer. Jon.