PostgreSQL JSONB: store, query and index JSON with SQL
10 steps · about 3 h 45 min · Intermediate
- JSON in PostgreSQL: json vs jsonb Explained (article, JSONPrism, 10 min)
Start by learning why jsonb is almost always the right column type, before you touch any operators.
- PostgreSQL: Documentation: 8.14. JSON Types (doc, PostgreSQL Global Development Group, 30 min)
The official reference for how json and jsonb are stored, plus containment, subscripting and indexing rules.
- PostgreSQL JSONB: Operators, Queries and Indexes (article, Coddy, 25 min)
Runnable examples of ->, ->>, @>, jsonb_set and GIN indexes give you hands-on practice with the basics.
- PostgreSQL JSONB: Operators, GIN Indexes, and Query Examples (article, DbSchema, 25 min)
A clear operator table makes the difference between returning jsonb and returning text easy to see.
- PostgreSQL JSONB: Indexing for Faster Queries with DbSchema (video, DbSchema (YouTube), 15 min)
Watching queries run, arrays turn into rows and indexes get added makes the written material concrete.
- PostgreSQL JSON and JSONB: Query, Index, and Update JSON Columns (article, Jsonic, 20 min)
Adds updates with jsonb_set and the existence operators ?, ?| and ?&, which come after reading and filtering.
- PostgreSQL: Documentation: JSON Functions and Operators (doc, PostgreSQL Global Development Group, 40 min)
The full reference for every operator, creation and processing function, and the jsonpath language.
- PostgreSQL JSON Index (article, Neon, 15 min)
A short walkthrough of creating a GIN index on a whole column or on one field.
- How to Index JSONB Data in PostgreSQL (article, Tiger Data, 25 min)
Compares GIN, B-tree expression and trigram indexes and shows when a query falls back to a sequential scan.
- PostgreSQL JSONB: Query, Update, and Index JSON Data (article, VisuaLeaf, 20 min)
The last step is to run EXPLAIN on a containment query and confirm that it uses the index.