JSONB vs JSON: When to Use Each
Choose between JSON (text, preserves whitespace) and JSONB (binary, indexable, deduplicated keys) for the right storage.
Two JSON Types in PostgreSQL
JSON— stores the exact text you put inJSONB— decomposed binary format, deduplicated keys, indexable
JSON: Text Storage
JSON preserves whitespace, key order, and duplicate keys. Reparse on every read. No GIN indexing. Almost never the right choice for new code.
INSERT INTO docs (data) VALUES ('{"a": 1, "a": 2}'::JSON);
SELECT data->'a' FROM docs; -- whatever the parser picksAll lessons in this course
- JSONB vs JSON: When to Use Each
- Path Operators: -> ->> @>
- Indexing JSONB with GIN
- Modelling: When JSONB Beats Normalisation