hn.today

PostgreSQL Extensions in Go

jespino.github.io160 points29 comments
Screenshot of PostgreSQL Extensions in Go

gopgext is an experimental toolkit for building PostgreSQL extensions in ordinary Go, compiled with TinyGo. Developers annotate Go functions with directives, and the tool generates the C glue, extension control file, and SQL installation script needed to load them into PostgreSQL. Its example defines SQL-callable greeting and shouting functions, including a PostgreSQL error with a specific SQLSTATE when the input is empty. The documentation describes mappings between Go and SQL types - including arrays, NULLs, rows, timestamps, UUIDs, and JSON - and support for custom and composite types. Go code can also run SQL through PostgreSQL’s SPI, inspect settings, log messages, and respond to query cancellation.

The toolkit aims well beyond simple functions: it supports triggers, aggregates, index operator classes and access methods, foreign data wrappers, and query hooks. Ports of PostgreSQL contrib modules such as pgcrypto, hstore, pg_stat_statements, and cube reportedly pass their upstream regression tests. Its runtime and generated glue are designed to let multiple Go extensions coexist in one backend, prevent PostgreSQL errors from unwinding through Go frames, and copy results into PostgreSQL-managed memory. The project uses a custom TinyGo target and runtime layer, with PostgreSQL’s PGXS build system compiling the C runtime. It is explicitly not production-ready: generated-code or runtime bugs could crash the server or corrupt data, and both its API and generated SQL may change without notice.

Read on jespino.github.io29 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Big Data Is Dead

Big Data Is Dead

Big data is not the main obstacle to useful insights: hardware has kept pace with data growth, while teams still struggle to make sense of their information. The author argues that organizations should focus on making data easier to understand and use, rather than buying tools built for ever-larger datasets. (motherduck.com)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.