Re: Constraint that compares and limits field values
От | MargaretGillon@chromalloy.com |
---|---|
Тема | Re: Constraint that compares and limits field values |
Дата | |
Msg-id | OF703239B0.5DF7FA0C-ON88257101.0066FC9D-88257101.00670C61@CHROMALLOY.COM обсуждение исходный текст |
Ответ на | Re: Constraint that compares and limits field values (Martijn van Oosterhout <kleptog@svana.org>) |
Список | pgsql-general |
>Martijn van Oosterhout <kleptog@svana.org> wrote on 01/25/2006 10:20:40 AM:
> On Wed, Jan 25, 2006 at 09:55:58AM -0800, MargaretGillon@chromalloy.com wrote:
>
> 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;
>
This works with a few modifications... needed an extra ( ) enclosing entire statement.
ALTER TABLE event
ADD CONSTRAINT two_nulls_1
CHECK (((CASE WHEN evenid1 IS NOT NULL THEN 1 ELSE 0 END) +
(CASE WHEN evevid1 IS NOT NULL THEN 1 ELSE 0 END) +
(CASE WHEN evreid1 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.
I am in version 7.3 and it will not let me cast the boolean to an integer.
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Margaret Gillon, IS Dept., Chromalloy Los Angeles, ext. 297
В списке pgsql-general по дате отправления: