Compare / pg_query_go
pg_query_go alternative: GoSQLX compared
pg_query_go wraps the real PostgreSQL parser (libpg_query) through CGo, so it is the exact PostgreSQL grammar.
- Approach
- Bindings to PostgreSQL’s own parser, converted to Go structs
- Dialect
- PostgreSQL only
- CGo required
- Yes (needs a C toolchain, complicates cross-compilation)
Pick pg_query_go when
- You need exact PostgreSQL grammar fidelity, including every syntax edge case, because it is the same parser the server uses.
- You only target PostgreSQL and already build with CGo.
- You need parse-tree compatibility with other pg_query bindings.
Pick GoSQLX when
- You want a pure Go dependency: no CGo, easy cross-compilation, WASM builds.
- You work with more than one dialect (PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, Snowflake, ClickHouse).
- You also want formatting, linting, security scanning, an LSP or an MCP server from the same library.
Parse speed, measured
End-to-end stage (SQL text to AST) · AMD EPYC 7763 64-Core Processor (linux/amd64) · go1.26.9 · median of 10 runs · measured 2026-11-02 · pg_query_go v6.2.5. Lower is faster.
| Query | GoSQLX | pg_query_go |
|---|---|---|
| Simple SELECT | 2,160 ns | 14,024 ns |
| SELECT with WHERE, ORDER BY, LIMIT | 5,119 ns | 42,716 ns |
| Two-table JOIN | 7,892 ns | 56,958 ns |
| GROUP BY with HAVING | 5,614 ns | 33,957 ns |
| IN subquery | 4,833 ns | 30,556 ns |
| Common table expression | 6,738 ns | 43,665 ns |
| Window function | 4,457 ns | 27,460 ns |
| Multi-JOIN analytical query | 21,006 ns | 152,898 ns |
| INSERT VALUES | 3,549 ns | 17,491 ns |
| UPDATE with WHERE | 3,190 ns | 18,254 ns |
| DELETE with WHERE | 2,045 ns | 11,437 ns |
Read with care. The libraries implement different SQL dialects and build different ASTs (pg_query_go wraps the real PostgreSQL parser through CGo and converts its tree to Go structs; Vitess, TiDB and xwb1989 implement MySQL grammars). Each figure is the end-to-end cost of turning the same SQL text into that library's AST on the stated hardware, not identical work. Results vary by query, so check the rows that resemble your workload.
Full table, methodology and reproduce steps: competitor benchmarks. Source: benchmarks/compare/results/latest.json, commit 3655a37.
What GoSQLX offers
Pure Go with no CGo, 8 dialects, 30 built-in lint rules, a formatter, a SQL injection scanner, an LSP server and an MCP server. Requires Go 1.26+.
Moving over? Migrating from pg_query.