Store and query JSON in PostgreSQL
8 steps · about 2 h 20 min · Intermediate
- Choose between json and jsonb (article, PostgreSQL docs, 20 min)
Explains storage differences and containment.
- Insert JSON documents (article, PostgreSQL docs, 10 min)
Shows how to load rows with JSON values.
- Use JSON operators, functions and paths (article, PostgreSQL docs, 35 min)
Reference for ->, ->>, @> and SQL/JSON path queries.
- Expand arrays into rows (article, PostgreSQL docs, 15 min)
Uses generate_series-style functions to unnest data.
- Index JSON with GIN (article, PostgreSQL docs, 20 min)
Makes containment queries fast.
- Index one JSON key with an expression index (article, PostgreSQL docs, 15 min)
A cheaper index when you query a single key.
- Use array functions beside JSON arrays (article, PostgreSQL docs, 10 min)
Gives the array tools to compare with jsonb array handling.
- Update rows holding JSON (article, PostgreSQL docs, 15 min)
Pairs UPDATE with jsonb_set for field changes.