# pganalyze/libpg_query

C library for accessing the PostgreSQL parser outside of the server environment

Repository: https://github.com/pganalyze/libpg_query
Canonical: https://ross.abutalabs.com/products/libpg_query
Language: C
License: BSD-3-Clause
License Family: permissive
Last push: 2026-08-25T16:47:02+00:00

## Health v2 (maintenance only)
Score: 90/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 99, release rhythm 72, longevity 100
- inputs: {"age_days": 4043, "days_push": 8, "days_rel": 105, "gap_med": 71.0, "n_releases_24m": 7}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 1478, forks 226 (observed 2026-08-28T04:04:50.564971+00:00)

## What it is
libpg_query is a C library that exposes PostgreSQL's actual SQL parser so applications can parse SQL queries and obtain the internal PostgreSQL parse tree outside the server. It also exposes the PostgreSQL lexer for tokenizing queries, and serves as the base for language bindings like pg_query.go, pglast, and pgsql-parser.

## Use cases
- parse postgres sql queries into a parse tree
- validate sql syntax without running a postgres server
- build a sql linter or formatter for postgresql
- tokenize sql queries for syntax highlighting
- analyze or rewrite postgres queries programmatically
- build language bindings for the postgres parser

## When to choose
- you need PostgreSQL-exact parsing behavior for SQL analysis, linting, or rewriting
- you are building a tool in C or a binding on top of the PostgreSQL grammar
- you cannot run or embed a full PostgreSQL server just to parse queries

## When to avoid
- you need a generic SQL parser for multiple dialects rather than PostgreSQL specifically
- you need to execute queries, not just parse them
- you want a pure high-level-language parser without a C build dependency

## Facets
- artifact type: library
- maturity: active
- function: parser, developer-tools
- domain: databases, parsers, developer-tools
- platform: windows, cross-platform, c
- tags: postgresql, sql-parser, parse-tree, sql-linting, query-analysis, linux, macos

## Member repositories
- pganalyze/libpg_query (main) score 90

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:04:50.564971+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T04:34:22.031659+00:00, confidence not recorded.
  - readme: https://github.com/pganalyze/libpg_query (fetched 2026-08-28T04:04:50.564971+00:00, sha 63ba886fccad)
- Data as of 2026-08-30T08:39:29.467469+00:00.
