gopgext: Writing PostgreSQL Extensions in Go
gopgext builds PostgreSQL extensions from plain Go code using TinyGo[1]. A function marked with //gopgext:function becomes a SQL function, and gopgext generates the C glue, the install script and the control file. Go types map to SQL types, and the standard library can be used.
Extensions can run SQL through SPI[2], return errors with SQLSTATE[3] codes, and write triggers, aggregates, index operator classes, index access methods and foreign data wrappers. Ports of PostgreSQL's contrib modules, such as pgcrypto and hstore, are said to pass upstream's regression tests. Several Go extensions can load in one backend, and PostgreSQL errors never unwind through Go frames.
The project uses the same approach as gokm, which builds Linux kernel modules in Go. Its C runtime is compiled by the host's own build system, which is PGXS[4] for PostgreSQL.
Repository gopgext github.com
Open source tool that builds PostgreSQL extensions from plain Go code using TinyGo, generating the C glue and SQL install files.
Read the original jespino.github.ioDiscussion
Discussion
Commenters mostly welcome the project as a way to make extensions easier to write, but some doubt that Go suits data-plane work, and one suggests plpgsql or pgrx instead. Asked whether it supports goroutines, a commenter says TinyGo gives a single-threaded binary without the full Go runtime, so goroutines are given up.
Links from the post and discussion
- gokm: Linux kernel modules in Go, same author jespino.github.io
- plgo: another Go-for-PostgreSQL extension project (comment) gitlab.com
Sources
-
jespino.github.io
PostgreSQL Extensions in Go
-
KRGeekNews KO
Go로 PostgreSQL 확장 개발하기



