Search Postgresql Archives

Re: Constraint that compares and limits field values

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

 



On Wed, Jan 25, 2006 at 09:55:58AM -0800, MargaretGillon@xxxxxxxxxxxxxx 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@xxxxxxxxx>   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.

Attachment: signature.asc
Description: Digital signature


[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