Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Performance & internals
Stage 5: Specialization

Part 14 / Topic 6 of 10

The SQL/JSON standard functions

The SQL standard's own spellings arrived across PostgreSQL 16–17, and they read like their names: JSON_EXISTS, JSON_VALUE (one scalar), JSON_QUERY (a fragment) —

SELECT event_id,
       JSON_VALUE(payload, '$.device') AS device,
       JSON_EXISTS(payload, '$.order_id') AS has_order
FROM events
ORDER BY event_id
LIMIT 3;
 event_id | device  | has_order 
----------+---------+-----------
        1 | mobile  | f
        2 | mobile  | f
        3 | desktop | t
(3 rows)

— and the headline, new in PostgreSQL 17: JSON_TABLE, which turns a JSON document into a real table expression, columns typed and named:

SELECT e.event_id, jt.device, jt.product_id
FROM events AS e,
     JSON_TABLE(e.payload, '$'
       COLUMNS (
         device     text    PATH '$.device',
         product_id integer PATH '$.product_id'
       )
     ) AS jt
WHERE e.event_type = 'view'
ORDER BY e.event_id;
 event_id | device  | product_id 
----------+---------+------------
        1 | mobile  |          1
        4 | desktop |          3
        6 | mobile  |          2
(3 rows)

JSON in, rows-and-columns out, joinable like anything else — the bridge between a document column and the entire relational toolkit. These standard forms travel across databases; the ->>/@> operators remain the idiomatic (and GIN-indexed) Postgres daily drivers.

🧪 Quick quiz — answer from memory, then check.

  1. JSON_VALUE vs JSON_QUERY?
  2. What does JSON_TABLE produce?
Show the answers
  1. VALUE returns one scalar; QUERY returns a JSON fragment (object/array).
  2. A table expression — typed, named columns extracted from the document, usable in FROM like any table.

Done here? The practice set for Part 14 — 6 exercises with solutions — is on the part page.

Search the guide