From: | Martijn van Oosterhout <kleptog(at)svana(dot)org> |
---|---|
To: | littlebutty <littlebutty(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: bit/integer operations in postgres |
Date: | 2006-01-01 16:59:13 |
Message-ID: | 20060101165913.GB627@svana.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, Dec 22, 2005 at 05:04:30PM -0800, littlebutty wrote:
> HERE IS WHAT I WANT TO DO:
> How do I setup a postgres constraint that will not allow an insert on
> the permission table with an integer value that has more than one bit
> set. In other words you could insert 1, 2, 4, 8, 16, 32, etc. because
> there is only a single bit on in all of those integers, but not insert
> 3, 5, 6, 7, 9, 15, 19, etc. because they have multiple???
Well, you could use the properties of two-complement arithmentic to do
it:
CHECK(value = (value & ((~value)+1)) )
Or perhaps you should look into the bit datatype with get_bit abd
set_bit.
Have a nice day,
--
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 | Andrus Moor | 2006-01-01 17:56:03 | pg_reload_conf() does not unset archive_command |
Previous Message | Scott Ribe | 2006-01-01 16:57:02 | Re: storing PDFs |