pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Rodger Donaldson <rodgerd@diaspora.gen.nz>
Cc: pgsql-sql@postgresql.org
Subject: Re: Cross-table constraints
Date: Wed, 29 Jan 2003 02:28:38 -0600
Message-ID: <20030129082838.GA19737@wolff.to> (raw)
In-Reply-To: <20030128070514.GB7146@diaspora.gen.nz>
References: <20030128070514.GB7146@diaspora.gen.nz>

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.



view thread (5+ messages)

Message-ID: <20030129082838.GA19737@wolff.to>
Permalink:  ../20030129082838.GA19737@wolff.to/
Also on:    postgresql.org/message-id/20030129082838.GA19737@wolff.to

 · 

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: bruno@wolff.to, rodgerd@diaspora.gen.nz
  Subject: Re: Cross-table constraints
  In-Reply-To: <20030129082838.GA19737@wolff.to>

* 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