jsonb_schema
jsonb_schema · jsonb with separately stored schema
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100555 | jsonb_schema | jsonb_schema | 1.0 | TYPE | PostgreSQL | C |
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
jsonb_schema separates the structural schema of a JSONB value from its scalar data and stores each distinct schema once in a database table. It can reduce storage when many documents share the same shape, but the packed representation is not self-contained and is not directly queryable like the original document.
Core Workflow
Pack documents before storage and unpack them when the original JSONB value is needed.
The packed value is a two-element JSONB array containing a schema identifier and encoded data. The shared schema bytes live in the extension-owned dictionary table.
Installed Objects
Version 1.0 creates the schema dictionary table, unique indexes for schema bytes and identifiers, two C-level schema/data conversion functions, and the pack and unpack wrappers. Packing inserts a new schema row on first use and reuses the identifier on conflict.
Storage and Lifecycle Boundaries
Measure with representative data before adopting the format: documents with repeated shapes may benefit, while highly variable shapes pay dictionary and encoding overhead. Indexes or expressions aimed at original JSON fields must unpack first, so ordinary JSONB query and index behavior does not transparently carry over to the packed column.
Packed rows depend on the exact identifier mapping in the dictionary table. Dump, restore, replicate, or move that table together with all packed values; copying only the JSONB column to another database can decode against the wrong schema or return no value. Do not delete dictionary rows still referenced by packed documents. The extension does not provide reference counting or schema garbage collection.
Packing writes shared metadata even though it is called as a function, so treat it as a write operation for transaction, permission, and concurrency planning. The extension is relocatable and declares no preload or restart requirement.