PostgreSQL JSONB: store, query and index JSON with SQL

10 steps · about 3 h 45 min · Intermediate

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. PostgreSQL JSON Index (article, Neon, 15 min)

    A short walkthrough of creating a GIN index on a whole column or on one field.

  9. 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.

  10. 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.