C library that provides PostgreSQL's SQL parser and scanner as a standalone component for external tools.
libpg_query is a C library that packages PostgreSQL's SQL parser and scanner as a standalone component. It allows external tools to parse PostgreSQL-compatible SQL queries and PL/pgSQL functions, returning the exact internal parse tree or tokenized output. This enables deep SQL analysis, formatting, linting, and tooling without requiring a running PostgreSQL server.
Developers building database tooling, SQL linters, query analyzers, syntax highlighters, or language servers that need accurate PostgreSQL SQL parsing. It's also used by projects that require query normalization or fingerprinting.
It provides the only way to get PostgreSQL's exact parser logic outside the server, ensuring full syntax compatibility. The library is battle-tested, supports multiple PostgreSQL versions, and serves as the foundation for many popular tools and language bindings.
C library for accessing the PostgreSQL parser outside of the server environment
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses the actual PostgreSQL server source code, ensuring 100% syntax accuracy for all PostgreSQL features, as highlighted in the description.
Returns queries as JSON parse trees matching PostgreSQL's internal representation, enabling deep analysis and manipulation, as shown in the usage example.
Supports scanning for tokenization, fingerprinting for normalization, and PL/pgSQL parsing, covering a wide range of tooling needs with dedicated functions.
Maintains branches aligned with recent PostgreSQL major versions, allowing tools to stay current with syntax changes, as detailed in the versions table.
Building the library requires compiling parts of PostgreSQL, taking up to 3 minutes and adding significant setup overhead, as noted in the installation instructions.
The core library is in C, necessitating language wrappers for integration in other ecosystems, which can introduce additional layers and maintenance burden.
Only supports PostgreSQL SQL syntax, making it unsuitable for tools that need to handle other database dialects like MySQL or SQLite without additional parsers.