Migrating JSONB columns in Go
When a JSONB column's shape changes, a custom sql.Scanner and driver.Valuer on the Go column type can read both the old and new formats while always writing the new one. incident.io used this to move conditions from a flat array to an array of condition groups, which was needed to support OR logic. Old flat arrays are wrapped in a single group on read, so backend and frontend work could proceed before the data migration finished. The backfill then reads and rewrites rows in batches of 1,000 via a GORM upsert (ON CONFLICT DO UPDATE), tracked by a temporary indexed conditions_migrated column, after which the compatibility scanner is removed.
Related posts
- SQL or NoSQL? Why not use both (with PostgreSQL)?
Supabase mediumAdeptPostgreSQL'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.
- Migrating from Fauna to Supabase
Supabase mediumAdeptWith Fauna sunsetting by the end of May 2025, a two-phase migration to Supabase keeps applications online. Phase one exports Fauna collections to S3 as JSON via the Fauna CLI, loads each document into a Postgres JSONB column with a supabase-js script, and rewrites FQL calls as PostgREST queries using JSON operators. Phase two normalizes the JSONB into relational tables with SQL (including LATERAL jsonb_array_elements for nested arrays) and switches API calls to the normalized columns. Tradeoffs include upfront schema planning, normalization scripts for nested documents, translating FQL/GraphQL to SQL, and adding indexes afterward.
- 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.
- pg_jsonschema: JSON Schema support for Postgres
Supabase mediumAdeptpg_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.
- 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.