Re: CHECK constraint on multiple tables - Mailing list pgsql-sql

From Mario Splivalo
Subject Re: CHECK constraint on multiple tables
Date
Msg-id 4AAE5141.70300@megafon.hr
Whole thread Raw
In response to Re: CHECK constraint on multiple tables  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: CHECK constraint on multiple tables  (Thomas Kellerer <spam_eater@gmx.net>)
Re: CHECK constraint on multiple tables  (Rob Sargent <robjsargent@gmail.com>)
List pgsql-sql
Tom Lane wrote:
> Mario Splivalo <mario.splivalo@megafon.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


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: CHECK constraint on multiple tables
Next
From: Thomas Kellerer
Date:
Subject: Re: CHECK constraint on multiple tables