Re: Constraint that compares and limits field values - Mailing list pgsql-general

From MargaretGillon@chromalloy.com
Subject Re: Constraint that compares and limits field values
Date
Msg-id OF5B4B2DFF.DA8A60CE-ON88257101.006744DD-88257101.0066E896@CHROMALLOY.COM
Whole thread Raw
In response to Re: Constraint that compares and limits field values  (Michael Fuhr <mike@fuhr.org>)
Responses Re: Constraint that compares and limits field values
List pgsql-general

>Michael Fuhr <mike@fuhr.org> wrote on 01/25/2006 10:25:38 AM:
> In 8.1, and in earlier versions if you create a cast from boolean
> to integer, you could do this:
>
> ALTER TABLE event
> ADD CONSTRAINT two_nulls_1 CHECK (
> (evenid1 IS NOT NULL)::int +
> (evevid1 IS NOT NULL)::int +
> (evreid1 IS NOT NULL)::int = 1);
>
> This works because the cast converts true to 1 and false to 0;
> you're adding up the number of true expressions and requiring that
> the sum equal 1 (i.e., that exactly one expression be true).
>
> --
> Michael Fuhr

I am in version 7.3 and it will not let me cast, I get message "ERROR: Cannot cast type boolean to integer". I will save this for when I upgrade.

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Margaret Gillon, IS Dept., Chromalloy Los Angeles, ext. 297

pgsql-general by date:

Previous
From: Philippe Ferreira
Date:
Subject: Re: My very first PL/pgSQL procedure...
Next
From: Patrick Hatcher
Date:
Subject: Trigger question: ROW or STATEMENT?