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

From Tom Lane
Subject Re: CHECK constraint on multiple tables
Date
Msg-id 15921.1252937895@sss.pgh.pa.us
Whole thread Raw
In response to CHECK constraint on multiple tables  (Mario Splivalo <mario.splivalo@megafon.hr>)
Responses Re: CHECK constraint on multiple tables  (Mario Splivalo <mario.splivalo@megafon.hr>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: Mario Splivalo
Date:
Subject: Re: CHECK constraint on multiple tables
Next
From: Mario Splivalo
Date:
Subject: Re: CHECK constraint on multiple tables