Re: How to count ones in a bit string?

Поиск
Список
Период
Сортировка
От Richard Broersma
Тема Re: How to count ones in a bit string?
Дата
Msg-id CABvLTWHuX7pDAzQH9bYwBp9qKfsDJfaCx9DVn1oraG8yR5sz9Q@mail.gmail.com
обсуждение исходный текст
Ответ на How to count ones in a bit string?  (Cheng <niechenghust@gmail.com>)
Ответы Re: How to count ones in a bit string?  (Michael Wood <esiotrot@gmail.com>)
Список pgsql-novice
There are probably fast better ways. But this is one way:

postgres=> SELECT LENGTH( REPLACE( CAST( B'101000000000000000000010'
AS TEXT ), '0', ''));
 length
--------
      3

On Tue, Feb 21, 2012 at 7:32 AM, Cheng <niechenghust@gmail.com> wrote:
> 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
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice



--
Regards,
Richard Broersma Jr.

В списке pgsql-novice по дате отправления:

Предыдущее
От: Cheng
Дата:
Сообщение: How to count ones in a bit string?
Следующее
От: Michael Wood
Дата:
Сообщение: Re: How to count ones in a bit string?