How to count ones in a bit string?

From: Cheng <niechenghust(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: How to count ones in a bit string?
Date: 2012-02-21 15:32:51
Message-ID: 4F43B923.1010402@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

For example, I have a bit string as:

B'101000000000000000000010'

How do I count the number of ones in it? In this example, it is 3.

Thanks,
Cheng

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Richard Broersma 2012-02-21 15:44:22 Re: How to count ones in a bit string?
Previous Message Ganesh Borse 2012-02-20 07:10:56 Request for help on selecting bytea columns using ODBC (windows) from Postgresql DB