pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mario Splivalo <mario.splivalo@megafon.hr>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-sql@postgresql.org
Subject: Re: CHECK constraint on multiple tables
Date: Mon, 14 Sep 2009 16:20:49 +0200
Message-ID: <4AAE5141.70300@megafon.hr> (raw)
In-Reply-To: <15921.1252937895@sss.pgh.pa.us>
References: <4AAE43F8.4000107@megafon.hr>
	<15921.1252937895@sss.pgh.pa.us>

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



view thread (21+ messages)  latest in thread

Message-ID: <4AAE5141.70300@megafon.hr>
Permalink:  ../4AAE5141.70300@megafon.hr/
Also on:    postgresql.org/message-id/4AAE5141.70300@megafon.hr

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mario.splivalo@megafon.hr, tgl@sss.pgh.pa.us
  Subject: Re: CHECK constraint on multiple tables
  In-Reply-To: <4AAE5141.70300@megafon.hr>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox