pg_json_diff
pg_json_diff : JSONB diff, JSON Patch, and JSON Merge Patch functions
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 4160 | pg_json_diff | pg_json_diff | 1.0 |
UTIL | MIT | C++ |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-r | No | Yes | No | Yes | yes | no |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.0 |
18 17 16 15 14 | pg_json_diff |
- |
| RPM | PIGSTY | 1.0 |
18 17 16 15 14 | pg_json_diff_$v |
- |
| DEB | PIGSTY | 1.0 |
18 17 16 15 14 | postgresql-$v-pg-json-diff |
- |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el8.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el9.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el9.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el10.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| el10.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| d12.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| d12.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| d13.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| d13.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u22.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u22.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u24.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u24.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u26.x86_64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
| u26.aarch64 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 | PIGSTY 1.0 |
Source
github.com/KhaledSMQ/pg-jsondiff
pg_json_diff-1.0-95cd668636ce.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
pg_json_diff 1.0 provides three immutable JSONB transformation functions backed by nlohmann/json: generate an RFC 6902 JSON Patch, apply such a patch, or apply an RFC 7386 merge patch. Use it for explicit document transformations, not as automatic conflict resolution or a stable audit-diff format.
Core Workflow
Generate a patch, store or inspect it, and verify that applying it produces the expected target:
Validate externally supplied patches before applying them and run the transformation in a transaction with application-level authorization.
Function Index
generate_json_diff(source, target)returns an RFC 6902 operation array.apply_patch(document, patch)supports add, remove, replace, move, copy, and test operations.merge_patch(document, patch)recursively merges objects; a null member removes a key and arrays are replaced rather than merged.
All three functions accept and return jsonb.
Operational Notes
Each call serializes PostgreSQL JSONB to text, parses it into a C++ JSON value, performs the operation, serializes again, and reparses the result as JSONB. Large or deeply nested documents therefore incur copying and parser cost. nlohmann/json and PostgreSQL JSONB have different numeric models, so test very large integers and high-precision decimals for fidelity. Patch errors are surfaced as general internal errors, and generated operation order or paths should not be treated as a canonical human audit record.