Re: database constraints

Поиск
Список
Период
Сортировка
От sklassen@commandprompt.com
Тема Re: database constraints
Дата
Msg-id 20041006083521.A32367@commandprompt.com
обсуждение исходный текст
Ответ на database constraints  (Ben <bench@silentmedia.com>)
Ответы Re: database constraints  (Bruno Wolff III <bruno@wolff.to>)
Список pgsql-general
* Ben <bench@silentmedia.com> [2004-10-06 08:23:11 -0700]:

> If I have have the table:
>
> create table foo
> (
>     a int references bar(id),
>     b int references baz(id)
> )
>
> ... how do I make sure one and only one of the columns a and b are
> non-null? Is it even reasonable?

ALTER TABLE foo ADD CONSTRAINT must_have_a_or_b CHECK (a::int IS NULL
AND b::int IS NOT NULL OR a::int IS NOT NULL AND b::int IS NULL);

--
Steven Klassen - Lead Programmer
Command Prompt, Inc. - http://www.commandprompt.com/
PostgreSQL Replication & Support Services, (503) 667-4564

В списке pgsql-general по дате отправления:

Предыдущее
От: Mark Gibson
Дата:
Сообщение: Re: Cache lookup failed for relation, when trying to DROP
Следующее
От: David Fetter
Дата:
Сообщение: Re: database constraints