Skip to content

bitstring_helpers

Helper C functions and aggregates for PostgreSQL bit varying data.

bitstring_helpers · Helper C functions and aggregates for PostgreSQL bit varying data.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100185bitstring_helpersbitstring_helpers1.0FUNCUnknownC

Usage

Sources:

bitstring_helpers 1.0 adds bit-counting, Hamming-distance, one-bit-neighbour, concatenation, conversion, and integer-shuffling helpers.

Bit-string operations

CREATE EXTENSION bitstring_helpers;
SELECT popcount(B'101101'::bit varying);
SELECT hamming_distance(B'101101'::bit varying, B'100001'::bit varying);
SELECT * FROM neighbours(B'101'::bit varying);

Use equal-length operands for Hamming distance. The neighbours function returns one value for every possible single-bit flip.

Conversions and aggregates

text2bitstring(text) converts a string of zeroes and ones to bit varying, and bit2text(bit varying) converts it back to text. The extension also creates explicit casts in both directions.

The installed aggregate surface is aconcat(anyelement) for collecting values into an array, concat(text) for concatenating text values, and concat(bit) for concatenating bit values. These declarations use PostgreSQL’s legacy aggregate syntax, so verify that CREATE EXTENSION succeeds on the target major before relying on them.

Caveats

  • shuffled_ints produces values from zero through limit minus one, despite the README describing a range starting at one.
  • A negative shuffle limit is used in an allocation before validation, and a large limit can exhaust backend memory. Never pass untrusted or unbounded values.
  • The shuffle uses a modulo-based process-global random generator and is biased; it is unsuitable for cryptographic, security, sampling, or fairness-sensitive work.
  • This 2013 code has no current PostgreSQL compatibility matrix, tests, or published license. Its legacy polymorphic aggregate declarations may require changes on modern PostgreSQL releases.

Table reader