JSONB
Definition
JSONB is a binary storage format for JSON data in PostgreSQL that allows for efficient indexing and faster processing. Unlike standard JSON, it stores data in a decomposed binary format, which avoids reparsing the text every time the data is accessed.
Where you hear it
In database schema design meetings, performance optimization discussions, and when working with semi-structured data in PostgreSQL.
Examples
We should use a JSONB column to store the flexible user preferences object.
Querying a JSONB field with a GIN index significantly improves search performance.
The query finds users whose preferences contain a dark theme, using the JSONB index.
Common mistake
Thinking that JSONB is always better than standard JSON; while it is faster to query, it takes slightly longer to write because the data must be converted into the binary format first.
Don't confuse with
JSONB is often confused with standard JSON; the key difference is that JSON stores data as an exact copy of the input text, while JSONB stores it in a decomposed binary format that supports indexing.
Say it at work
- In a meeting or chat
Let's switch this column to JSONB so we can create an index on the nested attributes.
- In an email or ticket
I have updated the schema to use JSONB for the metadata field to ensure faster query execution times.