Re: Foreign Unique Constraint

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: Foreign Unique Constraint
Дата
Msg-id 200703271758.42413.peter_e@gmx.net
обсуждение исходный текст
Ответ на Foreign Unique Constraint  ("Jon Horsman" <horshaq@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: array_to_string
Следующее
От: Tom Lane
Дата:
Сообщение: Re: select vs. select count