From: | MargaretGillon(at)chromalloy(dot)com |
---|---|
To: | Michael Fuhr <mike(at)fuhr(dot)org> |
Cc: | Richard Huxton <dev(at)archonet(dot)com>, MargaretGillon(at)chromalloy(dot)com, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Constraint that compares and limits field values |
Date: | 2006-01-25 18:51:23 |
Message-ID: | OF5B4B2DFF.DA8A60CE-ON88257101.006744DD-88257101.0066E896@CHROMALLOY.COM |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
>Michael Fuhr <mike(at)fuhr(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | MargaretGillon | 2006-01-25 18:52:55 | Re: Constraint that compares and limits field values |
Previous Message | Patrick Hatcher | 2006-01-25 18:44:27 | Trigger question: ROW or STATEMENT? |