2 ms·
Doesn't have a bitcount function unlike MySQL, which I ended up needing for one problem.
by collyw 10y ago
Doesn't have a bitcount function unlike MySQL, which I ended up needing for one problem.
- jfrisby 10y agoNot built in, but you can do this: CREATE OR REPLACE FUNCTION bitcount(i integer) RETURNS integer AS $$ DECLARE n integer; DECLARE amount integer; BEGIN amount := 0; FOR n IN 1..16 LOOP amount := amount + ((i >> (n-1)) & 1); END LOOP; RETURN amount; END $$ LANGUAGE plpgsql;
- collyw 10y agoThe reason for a bitcount was to check DNA sequences very quickly. Using a loop rather than a single CUP operation slowed it down a fair bit.