pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter_e@gmx.net>
To: pgsql-sql@postgresql.org
Cc: Jon Horsman <horshaq@gmail.com>
Subject: Re: Foreign Unique Constraint
Date: Tue, 27 Mar 2007 17:58:42 +0200
Message-ID: <200703271758.42413.peter_e@gmx.net> (raw)
In-Reply-To: <4f4c2a010703270621h5137a4e5rb515a9be9034a543@mail.gmail.com>
References: <4f4c2a010703270621h5137a4e5rb515a9be9034a543@mail.gmail.com>

Jon Horsman wrote:
> Basically table 1 and table 2 both have the concept of an extension
> that must be unique but the rest of the info in the tables are
> different.  I need to ensure that if i add an entry to table 1 with
> extension 1000 that it will fail if there is already an entry in
> table2 with the same extension.

Make a third table that contains all the extension and add two columns, 
one referencing table 1 and one referencing table 2, and then add a 
constraint that only one of the two can be not null.

It's not very pretty, but you can use views to make the access simpler.

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/



view thread (11+ messages)  latest in thread

Message-ID: <200703271758.42413.peter_e@gmx.net>
Permalink:  ../200703271758.42413.peter_e@gmx.net/
Also on:    postgresql.org/message-id/200703271758.42413.peter_e@gmx.net

 · 

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: peter_e@gmx.net, horshaq@gmail.com
  Subject: Re: Foreign Unique Constraint
  In-Reply-To: <200703271758.42413.peter_e@gmx.net>

* 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