
Aggregating Rows Into JSON With jsonb_agg in PostgreSQL
Build nested JSON documents from relational tables with jsonb_agg, jsonb_build_object and to_jsonb, avoid the join fan-out bug, and see which form is fastest.
Everything you need to level up your coding skills.

Build nested JSON documents from relational tables with jsonb_agg, jsonb_build_object and to_jsonb, avoid the join fan-out bug, and see which form is fastest.

JSON_TABLE turns nested JSON into typed rows in one clause. Paths, nested arrays, ordinality, EXISTS columns and ON ERROR rules, run on PostgreSQL 18.

Turn a JSONB array of objects into typed SQL columns with jsonb_to_recordset, jsonb_populate_recordset and jsonb_each, with the errors and edge cases.

Build typo tolerant search with pg_trgm in PostgreSQL: trigrams, similarity thresholds, GIN and GiST indexes, word similarity and full text fallback.

Search, count, filter and rebuild JSON arrays inside PostgreSQL JSONB, from containment tests to jsonb_array_elements, with timings for five tag lookups.

Build GIN indexes on JSONB, choose between jsonb_ops and jsonb_path_ops, and see the real size, build, insert and query costs on a 200,000-row table.

Add, rename, merge and delete keys and array elements in PostgreSQL JSONB with jsonb_set, jsonb_insert, || and minus, and see where each does nothing.

Change a single field in a PostgreSQL JSONB document with jsonb_set or subscripts, increment a counter, and avoid the lost-update and rewrite costs.

Stream a CSV from a web address straight into COPY with curl. See what a 404 and a cut off download do to a plain pipe, and the guards that fix it.

PostgreSQL reads deep JSONB values with #> and #>>, and filters with jsonpath. How array paths, missing keys, strict mode and wildcards actually behave.

Stream a gzipped CSV into PostgreSQL with gunzip and COPY, time it against unpacking first, and see what a truncated archive does to a pipe.

PostgreSQL 17 can skip rows with bad values during COPY. See ON_ERROR, REJECT_LIMIT and verbose logging in action, and the errors they do not cover.
We send one email when a new article is published. No spam.