pgbson

pgbson

pgbson : BSON data type and accessor functions for PostgreSQL

Overview

ID Extension Package Version Category License Language
3910
pgbson
pgbson
2.0.2
TYPE
MIT
C
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
See Also
pg_jsonschema
jsquery
jsonb_plperl
jsonb_plpython3u
mongo_fdw
documentdb
documentdb_core
documentdb_distributed

Release tag 2.0.2 still ships extension SQL version 2.0; PGXN dist name is bson, CREATE EXTENSION name is pgbson, RPM package root is postgresbson, and the runtime dependency is libbson.

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
2.0.2
18
17
16
15
14
pgbson -
RPM
PIGSTY
2.0.2
18
17
16
15
14
postgresbson_$v libbson
DEB
PIGSTY
2.0.2
18
17
16
15
14
postgresql-$v-pgbson -
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
el8.aarch64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
el9.x86_64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
el9.aarch64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
el10.x86_64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
el10.aarch64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
d12.x86_64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
d12.aarch64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
d13.x86_64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
d13.aarch64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
u22.x86_64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
u22.aarch64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
u24.x86_64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
u24.aarch64
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
PIGSTY 2.0.2
Package Version OS ORG SIZE File URL
postgresbson_18 2.0.2 el8.x86_64 pigsty 30.3 KiB postgresbson_18-2.0.2-1PIGSTY.el8.x86_64.rpm
postgresbson_18 2.0.2 el8.aarch64 pigsty 29.9 KiB postgresbson_18-2.0.2-1PIGSTY.el8.aarch64.rpm
postgresbson_18 2.0.2 el9.x86_64 pigsty 29.7 KiB postgresbson_18-2.0.2-1PIGSTY.el9.x86_64.rpm
postgresbson_18 2.0.2 el9.aarch64 pigsty 29.5 KiB postgresbson_18-2.0.2-1PIGSTY.el9.aarch64.rpm
postgresbson_18 2.0.2 el10.x86_64 pigsty 29.8 KiB postgresbson_18-2.0.2-1PIGSTY.el10.x86_64.rpm
postgresbson_18 2.0.2 el10.aarch64 pigsty 29.6 KiB postgresbson_18-2.0.2-1PIGSTY.el10.aarch64.rpm
postgresql-18-pgbson 2.0.2 d12.x86_64 pigsty 37.6 KiB postgresql-18-pgbson_2.0.2-1PIGSTY~bookworm_amd64.deb
postgresql-18-pgbson 2.0.2 d12.aarch64 pigsty 37.3 KiB postgresql-18-pgbson_2.0.2-1PIGSTY~bookworm_arm64.deb
postgresql-18-pgbson 2.0.2 d13.x86_64 pigsty 37.7 KiB postgresql-18-pgbson_2.0.2-1PIGSTY~trixie_amd64.deb
postgresql-18-pgbson 2.0.2 d13.aarch64 pigsty 37.3 KiB postgresql-18-pgbson_2.0.2-1PIGSTY~trixie_arm64.deb
postgresql-18-pgbson 2.0.2 u22.x86_64 pigsty 39.3 KiB postgresql-18-pgbson_2.0.2-1PIGSTY~jammy_amd64.deb
postgresql-18-pgbson 2.0.2 u22.aarch64 pigsty 38.9 KiB postgresql-18-pgbson_2.0.2-1PIGSTY~jammy_arm64.deb
postgresql-18-pgbson 2.0.2 u24.x86_64 pigsty 38.6 KiB postgresql-18-pgbson_2.0.2-1PIGSTY~noble_amd64.deb
postgresql-18-pgbson 2.0.2 u24.aarch64 pigsty 38.6 KiB postgresql-18-pgbson_2.0.2-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
postgresbson_17 2.0.2 el8.x86_64 pigsty 30.3 KiB postgresbson_17-2.0.2-1PIGSTY.el8.x86_64.rpm
postgresbson_17 2.0.2 el8.aarch64 pigsty 29.9 KiB postgresbson_17-2.0.2-1PIGSTY.el8.aarch64.rpm
postgresbson_17 2.0.2 el9.x86_64 pigsty 29.7 KiB postgresbson_17-2.0.2-1PIGSTY.el9.x86_64.rpm
postgresbson_17 2.0.2 el9.aarch64 pigsty 29.5 KiB postgresbson_17-2.0.2-1PIGSTY.el9.aarch64.rpm
postgresbson_17 2.0.2 el10.x86_64 pigsty 29.8 KiB postgresbson_17-2.0.2-1PIGSTY.el10.x86_64.rpm
postgresbson_17 2.0.2 el10.aarch64 pigsty 29.6 KiB postgresbson_17-2.0.2-1PIGSTY.el10.aarch64.rpm
postgresql-17-pgbson 2.0.2 d12.x86_64 pigsty 37.6 KiB postgresql-17-pgbson_2.0.2-1PIGSTY~bookworm_amd64.deb
postgresql-17-pgbson 2.0.2 d12.aarch64 pigsty 37.3 KiB postgresql-17-pgbson_2.0.2-1PIGSTY~bookworm_arm64.deb
postgresql-17-pgbson 2.0.2 d13.x86_64 pigsty 37.8 KiB postgresql-17-pgbson_2.0.2-1PIGSTY~trixie_amd64.deb
postgresql-17-pgbson 2.0.2 d13.aarch64 pigsty 37.3 KiB postgresql-17-pgbson_2.0.2-1PIGSTY~trixie_arm64.deb
postgresql-17-pgbson 2.0.2 u22.x86_64 pigsty 40.3 KiB postgresql-17-pgbson_2.0.2-1PIGSTY~jammy_amd64.deb
postgresql-17-pgbson 2.0.2 u22.aarch64 pigsty 39.9 KiB postgresql-17-pgbson_2.0.2-1PIGSTY~jammy_arm64.deb
postgresql-17-pgbson 2.0.2 u24.x86_64 pigsty 38.7 KiB postgresql-17-pgbson_2.0.2-1PIGSTY~noble_amd64.deb
postgresql-17-pgbson 2.0.2 u24.aarch64 pigsty 38.6 KiB postgresql-17-pgbson_2.0.2-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
postgresbson_16 2.0.2 el8.x86_64 pigsty 30.3 KiB postgresbson_16-2.0.2-1PIGSTY.el8.x86_64.rpm
postgresbson_16 2.0.2 el8.aarch64 pigsty 29.9 KiB postgresbson_16-2.0.2-1PIGSTY.el8.aarch64.rpm
postgresbson_16 2.0.2 el9.x86_64 pigsty 29.7 KiB postgresbson_16-2.0.2-1PIGSTY.el9.x86_64.rpm
postgresbson_16 2.0.2 el9.aarch64 pigsty 29.5 KiB postgresbson_16-2.0.2-1PIGSTY.el9.aarch64.rpm
postgresbson_16 2.0.2 el10.x86_64 pigsty 29.8 KiB postgresbson_16-2.0.2-1PIGSTY.el10.x86_64.rpm
postgresbson_16 2.0.2 el10.aarch64 pigsty 29.6 KiB postgresbson_16-2.0.2-1PIGSTY.el10.aarch64.rpm
postgresql-16-pgbson 2.0.2 d12.x86_64 pigsty 37.6 KiB postgresql-16-pgbson_2.0.2-1PIGSTY~bookworm_amd64.deb
postgresql-16-pgbson 2.0.2 d12.aarch64 pigsty 37.3 KiB postgresql-16-pgbson_2.0.2-1PIGSTY~bookworm_arm64.deb
postgresql-16-pgbson 2.0.2 d13.x86_64 pigsty 37.7 KiB postgresql-16-pgbson_2.0.2-1PIGSTY~trixie_amd64.deb
postgresql-16-pgbson 2.0.2 d13.aarch64 pigsty 37.3 KiB postgresql-16-pgbson_2.0.2-1PIGSTY~trixie_arm64.deb
postgresql-16-pgbson 2.0.2 u22.x86_64 pigsty 40.3 KiB postgresql-16-pgbson_2.0.2-1PIGSTY~jammy_amd64.deb
postgresql-16-pgbson 2.0.2 u22.aarch64 pigsty 39.9 KiB postgresql-16-pgbson_2.0.2-1PIGSTY~jammy_arm64.deb
postgresql-16-pgbson 2.0.2 u24.x86_64 pigsty 38.8 KiB postgresql-16-pgbson_2.0.2-1PIGSTY~noble_amd64.deb
postgresql-16-pgbson 2.0.2 u24.aarch64 pigsty 38.6 KiB postgresql-16-pgbson_2.0.2-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
postgresbson_15 2.0.2 el8.x86_64 pigsty 30.3 KiB postgresbson_15-2.0.2-1PIGSTY.el8.x86_64.rpm
postgresbson_15 2.0.2 el8.aarch64 pigsty 29.9 KiB postgresbson_15-2.0.2-1PIGSTY.el8.aarch64.rpm
postgresbson_15 2.0.2 el9.x86_64 pigsty 29.9 KiB postgresbson_15-2.0.2-1PIGSTY.el9.x86_64.rpm
postgresbson_15 2.0.2 el9.aarch64 pigsty 29.5 KiB postgresbson_15-2.0.2-1PIGSTY.el9.aarch64.rpm
postgresbson_15 2.0.2 el10.x86_64 pigsty 29.8 KiB postgresbson_15-2.0.2-1PIGSTY.el10.x86_64.rpm
postgresbson_15 2.0.2 el10.aarch64 pigsty 29.6 KiB postgresbson_15-2.0.2-1PIGSTY.el10.aarch64.rpm
postgresql-15-pgbson 2.0.2 d12.x86_64 pigsty 37.6 KiB postgresql-15-pgbson_2.0.2-1PIGSTY~bookworm_amd64.deb
postgresql-15-pgbson 2.0.2 d12.aarch64 pigsty 37.2 KiB postgresql-15-pgbson_2.0.2-1PIGSTY~bookworm_arm64.deb
postgresql-15-pgbson 2.0.2 d13.x86_64 pigsty 37.7 KiB postgresql-15-pgbson_2.0.2-1PIGSTY~trixie_amd64.deb
postgresql-15-pgbson 2.0.2 d13.aarch64 pigsty 37.2 KiB postgresql-15-pgbson_2.0.2-1PIGSTY~trixie_arm64.deb
postgresql-15-pgbson 2.0.2 u22.x86_64 pigsty 40.3 KiB postgresql-15-pgbson_2.0.2-1PIGSTY~jammy_amd64.deb
postgresql-15-pgbson 2.0.2 u22.aarch64 pigsty 39.8 KiB postgresql-15-pgbson_2.0.2-1PIGSTY~jammy_arm64.deb
postgresql-15-pgbson 2.0.2 u24.x86_64 pigsty 38.7 KiB postgresql-15-pgbson_2.0.2-1PIGSTY~noble_amd64.deb
postgresql-15-pgbson 2.0.2 u24.aarch64 pigsty 38.6 KiB postgresql-15-pgbson_2.0.2-1PIGSTY~noble_arm64.deb
Package Version OS ORG SIZE File URL
postgresbson_14 2.0.2 el8.x86_64 pigsty 30.2 KiB postgresbson_14-2.0.2-1PIGSTY.el8.x86_64.rpm
postgresbson_14 2.0.2 el8.aarch64 pigsty 29.9 KiB postgresbson_14-2.0.2-1PIGSTY.el8.aarch64.rpm
postgresbson_14 2.0.2 el9.x86_64 pigsty 29.8 KiB postgresbson_14-2.0.2-1PIGSTY.el9.x86_64.rpm
postgresbson_14 2.0.2 el9.aarch64 pigsty 29.5 KiB postgresbson_14-2.0.2-1PIGSTY.el9.aarch64.rpm
postgresbson_14 2.0.2 el10.x86_64 pigsty 29.8 KiB postgresbson_14-2.0.2-1PIGSTY.el10.x86_64.rpm
postgresbson_14 2.0.2 el10.aarch64 pigsty 29.6 KiB postgresbson_14-2.0.2-1PIGSTY.el10.aarch64.rpm
postgresql-14-pgbson 2.0.2 d12.x86_64 pigsty 37.5 KiB postgresql-14-pgbson_2.0.2-1PIGSTY~bookworm_amd64.deb
postgresql-14-pgbson 2.0.2 d12.aarch64 pigsty 37.2 KiB postgresql-14-pgbson_2.0.2-1PIGSTY~bookworm_arm64.deb
postgresql-14-pgbson 2.0.2 d13.x86_64 pigsty 37.6 KiB postgresql-14-pgbson_2.0.2-1PIGSTY~trixie_amd64.deb
postgresql-14-pgbson 2.0.2 d13.aarch64 pigsty 37.2 KiB postgresql-14-pgbson_2.0.2-1PIGSTY~trixie_arm64.deb
postgresql-14-pgbson 2.0.2 u22.x86_64 pigsty 40.3 KiB postgresql-14-pgbson_2.0.2-1PIGSTY~jammy_amd64.deb
postgresql-14-pgbson 2.0.2 u22.aarch64 pigsty 39.8 KiB postgresql-14-pgbson_2.0.2-1PIGSTY~jammy_arm64.deb
postgresql-14-pgbson 2.0.2 u24.x86_64 pigsty 38.6 KiB postgresql-14-pgbson_2.0.2-1PIGSTY~noble_amd64.deb
postgresql-14-pgbson 2.0.2 u24.aarch64 pigsty 38.6 KiB postgresql-14-pgbson_2.0.2-1PIGSTY~noble_arm64.deb

Source

pig build pkg pgbson;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pgbson;		# install via package name, for the active PG version

pig install pgbson -v 18;   # install for PG 18
pig install pgbson -v 17;   # install for PG 17
pig install pgbson -v 16;   # install for PG 16
pig install pgbson -v 15;   # install for PG 15
pig install pgbson -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pgbson;

Usage

Syntax:

CREATE EXTENSION pgbson;
SELECT bson_get_datetime(bson_column, 'msg.header.event.ts') FROM my_table;
SELECT (bson_column->'msg'->'header'->'event'->>'ts')::timestamp FROM my_table;

Source: README

pgbson adds a BSON data type to PostgreSQL together with functions and operators for creating, inspecting, and querying BSON documents. The upstream README positions it as a binary, richly typed alternative to JSON/JSONB with round-trip fidelity and first-class support for datetimes, numeric subtypes, and raw bytes.

Why BSON

The README highlights several BSON advantages over JSON:

  • datetimes are first-class values
  • numeric types remain distinct (int32, int64, float, decimal)
  • raw byte arrays are first-class
  • round-tripping preserves exact binary representation
  • native SDK support exists across many languages

Access Patterns

The extension exposes two styles of access:

Dotpath Accessors

These are the high-performance typed accessors documented upstream:

SELECT bson_get_datetime(bson_column, 'msg.header.event.ts') FROM my_table;
SELECT bson_get_bson(bson_column, 'msg.header.event') FROM my_table;

The README argues these are more memory-efficient than repeated arrow dereferences because they walk the BSON structure directly and materialize only the terminal value.

Arrow Operators

It also supports JSON-like operators:

SELECT (bson_column->'msg'->'header'->'event'->>'ts')::timestamp
FROM my_table;

JSON Interop

The BSON type can be cast to JSON using Extended JSON (EJSON) so type fidelity is preserved. This allows BSON values to be fed into JSON/JSONB functions and operators when needed:

SELECT (bson_get_bson(bson_column, 'msg.header.event')::jsonb) ?& ARRAY['id','type']
FROM my_table;

Notes

The README includes examples of end-to-end BSON round-tripping across Java, Kafka, Python, and PostgreSQL, emphasizing that the stored BSON payload can be retrieved byte-for-byte unchanged when cast back to bytea.

Last updated on