Skip to content

pg_bitcount

Bit-count scalar and aggregate functions for integers and bit strings.

pg_bitcount · Bit-count scalar and aggregate functions for integers and bit strings.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
101902pg_bitcountpg_bitcount0.0.3FUNCMITC

PostgreSQL · 11, 12, 13

Usage

Sources:

pg_bitcount Bit-count scalar and aggregate functions for integers and bit strings.

Enablement

Install the files for the intended server, then create pg_bitcount in the target database:

CREATE EXTENSION pg_bitcount;

Core Workflow

The following example is taken from the reviewed upstream documentation. Adapt object names, paths, credentials, and workload values before use.

-- Register the extension in PostgreSQL
create extension pg_bitcount version '0.0.3';

-- Use the pg_bitcount function
select public.pg_bitcount(127::bit(8)); -- 7
select public.pg_bitcount(B'101010101'); -- 5
select public.pg_bitcount((17^15)::bigint::bit(128) << 64 | (17^14)::bigint::bit(128)); -- 58

-- Use the pg_int_to_bit_agg aggregate using a bit string of size 24
select public.pg_bitcount(public.pg_int_to_bit_agg(i::int, 24)) from (select generate_series(2, 8) as i) data; -- 7

Main Objects

The reviewed install surface includes these prominent objects:

ObjectKindOperational role
public.pg_bitcountFUNCTIONCallable function from the reviewed install surface.
public.pg_int_to_bit_aggAGGREGATEAggregate exposed by the extension.
public.pg_int_to_bit_agg_transfnFUNCTIONCallable function from the reviewed install surface.

Operations and Boundaries

  • The verified PostgreSQL-major evidence covers 11, 12, 13; do not infer unlisted majors.
  • Catalog lifecycle is archived; test upgrades, dump/restore, and server compatibility before production use.

Table reader