
Arrays and Custom Types in Go With Postgres and pgx Codecs
Use PostgreSQL arrays and enums from Go with pgx: slices for text[] and int[], ANY and @> queries, NULL versus empty arrays and a string type for an enum.
Tag
8 articles

Use PostgreSQL arrays and enums from Go with pgx: slices for text[] and int[], ANY and @> queries, NULL versus empty arrays and a string type for an enum.

Store and query JSONB from Go with pgx: write structs, scan into structs and maps, filter with @> and ->>, update with jsonb_set and index with GIN.

Run Go tests against real PostgreSQL fast: migrate once into a template database, clone a private database per test, run in parallel and drop after.

Connect Go to PostgreSQL with pgx: a pgxpool for native use, the database/sql adapter for the standard API, pool sizing, timeouts and a wrong password.

Retry PostgreSQL serialization failures and deadlocks in Go: detect SQLSTATE 40001 and 40P01 with pgconn and rerun the whole transaction. Eight workers shown.

Handle time zones between Go and PostgreSQL: timestamptz keeps the instant, timestamp keeps a wall clock, and the session zone only changes display.

See isolation levels in Go on PostgreSQL: a non-repeatable read at Read Committed, write skew at Repeatable Read, and the error Serializable raises instead.

Build a Go search endpoint on PostgreSQL full text search: a weighted tsvector, GIN index, ranking, snippets, and a trigram fallback for typos.