Re: Foreign Unique Constraint - Mailing list pgsql-sql

From Peter Eisentraut
Subject Re: Foreign Unique Constraint
Date
Msg-id 200703271758.42413.peter_e@gmx.net
Whole thread Raw
In response to Foreign Unique Constraint  ("Jon Horsman" <horshaq@gmail.com>)
List pgsql-sql
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/


pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: array_to_string
Next
From: Tom Lane
Date:
Subject: Re: select vs. select count