Re: CHECK constraint on multiple tables

From: Rob Sargent <robjsargent(at)gmail(dot)com>
To: Mario Splivalo <mario(dot)splivalo(at)megafon(dot)hr>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-sql(at)postgresql(dot)org
Subject: Re: CHECK constraint on multiple tables
Date: 2009-09-16 03:34:16
Message-ID: 4AB05CB8.1040306@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Mario Splivalo wrote:
> Tom Lane wrote:
>
>> Mario Splivalo <mario(dot)splivalo(at)megafon(dot)hr> 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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Psicopunk 2009-09-16 09:01:10 Re: hardware information
Previous Message Martie Krukkeland 2009-09-15 14:38:28 Re: hardware information