Efficiently determining the number of bits set in the contents of a VARBIT field

From: Allan Kamau <allank(at)sanbi(dot)ac(dot)za>
To: pgsql-sql(at)postgresql(dot)org
Subject: Efficiently determining the number of bits set in the contents of a VARBIT field
Date: 2008-07-26 13:17:56
Message-ID: 488B2404.7080106@sanbi.ac.za
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi all,
Am looking for a fast and efficient way to count the number of bits set
(to 1) in a VARBIT field. I am currently using
"LENGTH(REGEXP_REPLACE(CAST(a.somefield_bit_code AS TEXT),'0','','g'))".

Allan.

Browse pgsql-sql by date

  From Date Subject
Next Message Giorgio Valoti 2008-07-26 20:20:41 Re: Select default values
Previous Message Volkan YAZICI 2008-07-26 05:48:11 Re: Test if a table is present