Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id A634B634DF2 for ; Wed, 16 Sep 2009 00:34:31 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 89066-01 for ; Wed, 16 Sep 2009 03:34:20 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) by mail.postgresql.org (Postfix) with ESMTP id A5A35632A67 for ; Wed, 16 Sep 2009 00:34:20 -0300 (ADT) Received: from in02.mta.xmission.com ([166.70.13.52]) by out02.mta.xmission.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1MnlHe-0003vJ-12; Tue, 15 Sep 2009 21:34:18 -0600 Received: from rsargent.dsl.xmission.com ([199.104.125.126] helo=[192.168.0.2]) by in02.mta.xmission.com with esmtp (Exim 4.69) (envelope-from ) id 1MnlHd-0005DH-7D; Tue, 15 Sep 2009 21:34:17 -0600 Message-ID: <4AB05CB8.1040306@gmail.com> Date: Tue, 15 Sep 2009 21:34:16 -0600 From: Rob Sargent User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: Mario Splivalo CC: Tom Lane , pgsql-sql@postgresql.org References: <4AAE43F8.4000107@megafon.hr> <15921.1252937895@sss.pgh.pa.us> <4AAE5141.70300@megafon.hr> In-Reply-To: <4AAE5141.70300@megafon.hr> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-XM-SPF: eid=; ; ; mid=; ; ; hst=in02.mta.xmission.com; ; ; ip=199.104.125.126; ; ; frm=robjsargent@gmail.com; ; ; spf=neutral X-XM-DomainKey: sender_domain=gmail.com; ; ; sender=robjsargent@gmail.com; ; ; status=no signature X-SA-Exim-Connect-IP: 199.104.125.126 X-SA-Exim-Mail-From: robjsargent@gmail.com X-Spam-DCC: XMission; sa04 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Mario Splivalo X-Spam-Relay-Country: Subject: Re: CHECK constraint on multiple tables X-SA-Exim-Version: 4.2.1 (built Thu, 25 Oct 2007 00:26:12 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200909/65 X-Sequence-Number: 33130 Mario Splivalo wrote: > Tom Lane wrote: > >> Mario Splivalo writes: >> >>> I have two tables, tableA and tableB: >>> CREATE TABLE tableA (idA integer primary key, email character varying >>> unique); >>> CREATE TABLE tableB (idB integer primary key, email character varying >>> unique); >>> >>> Now, I want to create check constraint in both tables that would >>> disallow records to either table where email is 'mentioned' in other table. >>> >> Have you considered refactoring so there's only one table? >> > > Unfortunately I can't do that, due to the > object-relational-mapper-wrapper-mambo-jumbo. > > The only 'logical' idea that I can think of is separating emails to the > third table, and then use UNIQUE constraint on the email field on that > table, and then use FK constraint so that email fields in tables tableA > and tableB points to the email in the table emails. > > Mario > > Is that wrapper hibernate by any chance? If so you might try adding a discriminator column to the single table TL suggested and map each class accordingly.