select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

FUNCTIONS / BINARY STRING FUNCTIONS AND OPERATORS

Returns the number of bits set in the binary string (also known as “popcount”).

Signatures & examples

bit_count ( bytes bytea ) → bigint
Returns the number of bits set in the binary string (also known as popcount).
bit_count('\x1234567890'::bytea) → 15
bit_count ( bit ) → bigint
Returns the number of bits set in the bit string (also known as popcount).
bit_count(B'10111') → 4
Version history 1
  1. PG 13 → 14added

Definition snapshot: 2026-09-14T13:14:25.684213+00:00@99e6866c · English manual source