Re: Cross-table constraints - Mailing list pgsql-sql

From Bruno Wolff III
Subject Re: Cross-table constraints
Date
Msg-id 20030129082838.GA19737@wolff.to
Whole thread Raw
In response to Cross-table constraints  (Rodger Donaldson <rodgerd@diaspora.gen.nz>)
List pgsql-sql
On Tue, Jan 28, 2003 at 20:05:15 +1300, Rodger Donaldson <rodgerd@diaspora.gen.nz> wrote:
> 
> The problem: I have two tables, add_queue and sites, on a postgresql
> 7.2.x database.  add_queue is where items go to be reviewed by a human
> before being moved into sites.  One of the things I'd like to do is to
> cut down on the amount of work done by humans filtering out dupes and
> sundry other problems.

Create a third table with three id columns. The first is the primary
key and the other two tables should reference it. The second and third
should allow for nulls and each reference the id field in one of the
other two tables. You also need a table constraint that forces exactly
one of these two fields to be null. And two more constraints to make
sure they match the primary key when they aren't null.

This should make sure each id is in exactly one of the two original tables
and that any id in the two original tables is in the new table.


pgsql-sql by date:

Previous
From: Abdul Wahab Dahalan
Date:
Subject: USING INDEX
Next
From: "David Durst"
Date:
Subject: Re: LONG - Question on dealing w/ numerics