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

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?

Cross-table constraints are a really bad idea unless you can express
them as foreign keys.  There's a lot of "secret sauce" in the FK
mechanism that isn't available to user-written constraints.

			regards, tom lane



view thread (21+ messages)  latest in thread

Message-ID: <15921.1252937895@sss.pgh.pa.us>
Permalink:  ../15921.1252937895@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/15921.1252937895@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, mario.splivalo@megafon.hr
  Subject: Re: CHECK constraint on multiple tables
  In-Reply-To: <15921.1252937895@sss.pgh.pa.us>

* 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