PostgreSQL Extensions in Go
- ID
- 49312
- Status
- summarized
- Published
- 22 Nov 2026, 1:08 AM
- Fetched
- 23 Nov 2026, 8:15 AM
- Provider
- Hacker News
- Category
- dev-community
- Original URL
- https://jespino.github.io/gopgext/
- Source URL
- https://hnrss.org/best
Summary
- Score
- 7.0
- Created
- 23 Nov 2026, 8:15 AM
- Tags
- Audience
- developersdatabase_learnersvibe_coders
What happened
gopgext is an experimental tool that builds PostgreSQL extensions from plain Go code via TinyGo, turning a function marked with a `//gopgext:function` comment into a SQL function while it writes the C glue, `.control` file and install script for you. It covers more than scalar functions — triggers, aggregates, GiST/GIN/SP-GiST/BRIN operator classes, index access methods, foreign data wrappers and query hooks — and exposes SPI for running SQL plus SQLSTATE-coded errors and query-cancellation handling. The author reports ports of contrib modules (pgcrypto, hstore, pg_stat_statements, cube) passing upstream regression tests, and points to gokm, a sibling project that builds Linux kernel modules the same way.
Why it matters
If the only thing stopping you from writing a Postgres extension was C, this removes that barrier — the Go standard library (fmt, regexp, encoding/json, crypto/*, generics, iterators) is available. But the author explicitly says don't use it in production: a bug in generated code or the Go runtime runs inside the server process and can crash it or corrupt data, and the API and generated SQL may change without notice. Treat it as a prototyping tool on a throwaway database, not something you ship to a shared production cluster.
Discussion angle
The safety model is the interesting part: the project claims PostgreSQL errors never unwind through Go frames and that results are copied into PostgreSQL memory, and that several Go extensions can coexist in one backend. Ask whether you'd trust a TinyGo runtime inside your database process, and what extension you'd actually write first if the C barrier disappeared.