Search Postgresql Archives

Re: Constraint that compares and limits field values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




>Michael Fuhr <mike@xxxxxxxx> 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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux