Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Neon 3 min read How-to mediumAdept

Understanding the new JSON capabilities in Postgres 16

Postgres 16 expands SQL/JSON syntax with JSON_ARRAY(), JSON_ARRAYAGG() and the IS JSON predicate, each shown with runnable examples. JSON_ARRAY builds an array from a list of values or from a subquery result. JSON_ARRAYAGG aggregates column values across rows into a single array and skips NULLs. IS JSON tests whether text parses as JSON and can check for a specific type (SCALAR, OBJECT, ARRAY) or for unique keys. Neon now supports Postgres 16, so these features can be tried there.

Assumes: SQL basicsJSON

Related posts

  • SQL or NoSQL? Why not use both (with PostgreSQL)?

    Supabase mediumAdept

    PostgreSQL's JSONB columns let an app store nested, variable-length data (here, a daily food, water and exercise log) as a single row instead of spreading it across several normalized tables, while keeping SQL available for analysis. A worked example builds a calendar table with JSONB log fields and inserts a whole day in one statement. It then uses jsonb_array_elements with the -> and ->> operators to flatten the arrays into rows. Because aggregates cannot wrap set-returning functions, the flattened query goes into a CTE before summing daily calories or filtering for specific items.

  • What's New in PostgreSQL 14?

    Render mediumAdept

    PostgreSQL 14 adds jsonb subscripting, which lets queries read, filter and update nested JSONB values with JavaScript-like bracket syntax instead of path operators such as #>. It also adds multirange types, which store several non-overlapping ranges, such as an all-day meeting with a lunch break, as a single value rather than multiple rows. Concurrent connection handling is notably faster: pganalyze's pgbench tests showed roughly 20% higher throughput at 5,000 connections and 50% at 10,000 compared with PostgreSQL 13. Render offered PostgreSQL 14 on release day.

  • Top 3 features in Postgres 17

    Neon mediumAdept

    Postgres 17 adds RETURNING support to MERGE (with a merge_action() function that reports whether each row was inserted, updated or deleted), SQL/JSON functions including JSON_TABLE for turning JSON into relational rows, and performance work. On the performance side, vacuum uses a new data structure that cuts memory use by up to 20x and lifts the 1GB cap, and B-tree scans handle IN-lists faster. Neon engineers contributed to EXPLAIN (SERIALIZE), parallel BRIN index builds, direct TLS handshakes, event triggers on client connect, and amcheck validation of B-tree uniqueness.

  • pg_jsonschema: JSON Schema support for Postgres

    Supabase mediumAdept

    pg_jsonschema is a Postgres extension that validates `json` and `jsonb` values against a JSON Schema through two functions, `json_matches_schema` and `jsonb_matches_schema`. Used inside a check constraint, it keeps the flexibility of document columns, such as storing raw webhook payloads instead of normalizing them into many joined tables, while still enforcing type, required-field and no-extra-properties rules. In the example, an unconstrained `json` column handled only 2 of 8 test inputs correctly, and the schema-backed check constraint handled all 8. It is available on Supabase via `create extension pg_jsonschema` or through Docker Compose.

  • pg_graphql: Postgres functions now supported

    Supabase mediumAdept

    pg_graphql 1.4+ reflects Postgres user-defined functions into the GraphQL schema, giving custom SQL logic a GraphQL entry point. Argument nullability follows from defaults, and function volatility decides placement: immutable and stable functions become Query fields, while volatile functions become Mutations. Functions returning setof a table type get Relay-style pagination, filtering, sorting and foreign-key relationships automatically. Overloaded, variadic, void-returning, nameless-argument, array-argument and tuple-argument functions are not yet supported.

The quest for software engineering knowledge.

Look:
Layout: