SQLTy vs pggen¶
Both give Go typed PostgreSQL queries from SQL you write. pggen
runs your .sql files against a real PostgreSQL (Docker or a DSN) and generates Go code for pgx.
SQLTy generates nothing: you write sqlty.SQL[Row, func(email string)] constants and your own
structs, and go vet with the SQLTy analyzer checks them against your schema files.
Quick comparison¶
| pggen (632aa8e) | SQLTy for Go (preview) | |
|---|---|---|
| Output | Generated functions and row structs | No generated code; your structs are checked |
| Needs a database | Yes, to generate | No |
| Driver | pgx v4 | pgx v5 |
| Nullability | Inferred, "rudimentary" by its own README: in a LEFT JOIN query, the NOT NULL u.email and COUNT(*) OVER () came out as pointers |
Inferred: only the joined side and nullable columns are optional |
| Parameters | A struct once a query has 3 or more | A func(...) type; arguments checked at the call |
| Type overrides | --go-type |
Not yet |
| Lint rules | None | Over 70, shared with Python |
| Where it runs | pggen gen |
go vet, golangci-lint |
Where SQLTy is stronger¶
- No Docker or database to generate or check.
- pgx v5 (pggen targets v4).
- More precise nullability, and the lint rules shared with Python.
Where pggen is stronger¶
- It is stable, and generated signatures need no analyzer. SQLTy for Go is a preview.
- The database decides types, including extensions and composite types.
--go-typeoverrides.
Which should you choose?¶
Choose pggen if you are happy on pgx v4 and generating from a live database. Choose SQLTy if you want your own structs, pgx v5 and no database in the build.
What SQLTy is missing¶
- Type overrides, named parameters,
database/sql, MySQL and SQLite. - A prebuilt
sqlty-vetfor Windows and Alpine Linux, and a golangci-lint plugin that builds without a checkout of the repository.
Common questions¶
Does SQLTy for Go need a database?¶
No. The analyzer reads the schema files that sqlty.toml names, in go vet and golangci-lint.
Sources¶
- pggen README and
go.mod(pgx v4.18.3) at 632aa8e; run on PostgreSQL 17 with one schema and 4 queries (2026-12-01)