Skip to content

jsonb_slice

Experimental partial reads of external uncompressed JSONB values

jsonb_slice · Experimental partial reads of external uncompressed JSONB values

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102450jsonb_slicejsonb_slice0.6.0FEATPostgreSQLC

PostgreSQL · 16, 18, 19

Usage

Sources:

jsonb_slice 0.6.0 is a research extension for reading one field or path from a large JSONB value without fetching the entire value when storage permits it. Upstream explicitly advises against production use. CI covers PostgreSQL 16; the optimized TOAST reader is documented for 18 and 19.

Explicit Accessors

A superuser creates the relocatable C extension. Explicit functions and operators need no preload:

CREATE EXTENSION jsonb_slice;
SELECT jsonb_slice_get('{"name":"Ada","active":true}'::jsonb, 'name');
SELECT jsonb_slice_get_text('["first","last"]'::jsonb, -1);
SELECT jsonb_slice_path_text('{"profile":{"name":"Ada"}}'::jsonb,
                             ARRAY['profile','name']);
SELECT '{"profile":{"name":"Ada"}}'::jsonb ~#>> ARRAY['profile','name'];

jsonb_slice_get and jsonb_slice_get_text accept a key or integer index; negative indices count from the end. jsonb_slice_path and jsonb_slice_path_text traverse a text-array path. Operators ~> and ~#> return JSONB; ~>> and ~#>> return SQL text. Missing locations return SQL NULL. JSONB results preserve JSON null, whereas text results convert it to SQL NULL.

Optional Transparent Mode

Load the hook before planning a query and enable it per session:

LOAD 'jsonb_slice';
SET jsonb_slice.transparent = on;

The default is off. For persistent loading, add the library to session_preload_libraries while preserving other entries and reconnect. Creating the extension alone does not activate the hook in every session. Eligible common plan expressions using built-in JSONB accessors can then call the extension; expressions outside the supported traversal retain the built-in implementation.

Storage and Upgrade Boundaries

Partial reads require an external, uncompressed value. Inline or compressed values use PostgreSQL’s complete-value functions. Transparent mode additionally requires an eligible relation with a JSONB column declared STORAGE EXTERNAL; changing that setting alone does not rewrite old values. On PostgreSQL 18/19 with heap TOAST storage, 0.6.0 reuses one TOAST scan per lookup. jsonb_slice.fetch_path = 'portable' selects the older slice reader. No general speedup is guaranteed.

After installing matching files, use the supplied 0.5.0-to-0.6.0 upgrade or earlier sequential chain, and reconnect sessions to load the new library:

ALTER EXTENSION jsonb_slice UPDATE TO '0.6.0';

Table reader