Re: CHECK constraint on multiple tables

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Mario Splivalo <mario(dot)splivalo(at)megafon(dot)hr>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: CHECK constraint on multiple tables
Date: 2009-09-14 14:18:15
Message-ID: 15921.1252937895@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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?

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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Mario Splivalo 2009-09-14 14:20:49 Re: CHECK constraint on multiple tables
Previous Message Mario Splivalo 2009-09-14 13:58:12 Re: CHECK constraint on multiple tables