Re: Bit count

From: Jasen Betts <jasen(at)xnet(dot)co(dot)nz>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Bit count
Date: 2009-11-26 11:04:21
Message-ID: helnbl$ggh$1@reversiblemaps.ath.cx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On 2009-11-24, Nathaniel Trellice <naptrel(at)yahoo(dot)co(dot)uk> wrote:
> I'd like to use an integer column (16 bits will suffice) to hold a bit-field. I'd like to be able to efficiently count the number of bits set in this field.
>
> Is there a built-in function call I can use? (I can't find one in the manual).

convert it to a text representation of the binary value use regexp_replace to remove the 0s take the length.

> If not, can anyone recommend the most efficient way within postgres to implement the kind of bit-counting tricks found at:

postgres functions can be written in C (if you have superuser
priviledges) seems like overkill though.

In response to

  • Bit count at 2009-11-24 15:47:05 from Nathaniel Trellice

Browse pgsql-novice by date

  From Date Subject
Next Message Nathaniel Trellice 2009-11-26 14:27:20 Re: Bit count
Previous Message Rikard Bosnjakovic 2009-11-26 05:00:03 Re: Merging two GROUP BY-queries