Re: Constraint that compares and limits field values

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: Constraint that compares and limits field values
Дата
Msg-id 20060125182040.GD31698@svana.org
обсуждение исходный текст
Ответ на Re: Constraint that compares and limits field values  (MargaretGillon@chromalloy.com)
Ответы Re: Constraint that compares and limits field values  (MargaretGillon@chromalloy.com)
Список pgsql-general
On Wed, Jan 25, 2006 at 09:55:58AM -0800, MargaretGillon@chromalloy.com wrote:
> ALTER TABLE event
> ADD CONSTRAINT two_nulls_1 CHECK
> ((evenid1 IS NULL) AND (evevid1 IS NULL) and (evreid1 IS NOT NULL)) OR
> ((evenid1 IS NULL) AND (evevid1 IS NOT NULL) and (evreid1 IS NULL)) OR
> ((evenid1 IS NOT NULL) AND (evevid1 IS NULL) and (evreid1 IS  NULL))

Parhaps something like:

CHECK((CASE WHEN evenid1 IS NOT NULL THEN 1 ELSE 0 END) +
      (CASE WHEN evenid2 IS NOT NULL THEN 1 ELSE 0 END) +
      (CASE WHEN evenid3 IS NOT NULL THEN 1 ELSE 0 END)) = 1;

If you can find a function to turn a bool into an int it becomes even
easier.

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Вложения

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

Предыдущее
От: "gianni.zammarchi@tiscali.it"
Дата:
Сообщение: xml support on win32 postgres
Следующее
От: Michael Fuhr
Дата:
Сообщение: Re: Constraint that compares and limits field values