From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
---|---|
To: | MargaretGillon(at)chromalloy(dot)com |
Cc: | Michael Fuhr <mike(at)fuhr(dot)org>, Richard Huxton <dev(at)archonet(dot)com>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Constraint that compares and limits field values |
Date: | 2006-01-25 18:20:40 |
Message-ID: | 20060125182040.GD31698@svana.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, Jan 25, 2006 at 09:55:58AM -0800, MargaretGillon(at)chromalloy(dot)com 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(at)svana(dot)org> 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.
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2006-01-25 18:25:38 | Re: Constraint that compares and limits field values |
Previous Message | gianni.zammarchi@tiscali.it | 2006-01-25 18:05:19 | xml support on win32 postgres |