Re: count the number of bits set to 1 in a bit string field
В списке pgsql-general по дате отправления:
| От | Ragnar |
|---|---|
| Тема | Re: count the number of bits set to 1 in a bit string field |
| Дата | |
| Msg-id | 1184541609.5778.159.camel@localhost.localdomain обсуждение исходный текст |
| Ответ на | count the number of bits set to 1 in a bit string field (Rajarshi Guha <rguha@indiana.edu>) |
| Ответы |
Re: count the number of bits set to 1 in a bit string field
|
| Список | pgsql-general |
On sun, 2007-07-15 at 15:35 -0400, Rajarshi Guha wrote:
> Hi, is there a built in function that will give me the number of bits
> that are set to 1 in a bit string field?
no, but it should be trivial to do with pl/pgsql
a naive implementation could be:
create or replace function bitsetlen(bit) returns int as $$
declare i int;
c int;
begin
c:=0;
for i in 1..length($1) loop
if substring($1,i,1)=B'1' then
c:=c+1;
end if;
end loop;
return c;
end;
$$ language plpgsql;
gnari
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера