sqlparser

Extensible SQL lexer and parser for Rust, conforming to ANSI SQL:2011

Library
Cargo
v0.62.0
3,427stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
81/100Excellent
Development Activity88
Maintenance52
Community84
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture84
Code Quality85
Innovation78
Learning Curve70

sqlparser is a Rust crate providing a lexer and recursive-descent parser for SQL that conforms to the ANSI/ISO SQL standard while supporting a growing set of vendor-specific dialects (PostgreSQL, MySQL, Snowflake, BigQuery, ClickHouse, DuckDB, Databricks, Hive, MSSQL, Oracle, and more). It parses SQL text into a strongly-typed AST and can regenerate the original SQL from that AST, preserving syntax (aside from comments and whitespace normalization) for tooling that needs faithful round-tripping.

As an Apache Software Foundation project living under the DataFusion umbrella, it deliberately stays a pure syntax parser with no semantic analysis, making it a reusable foundation rather than a full query engine. It’s the SQL front-end for Apache DataFusion, Polars, GlueSQL, Opteryx, PRQL, and several other query engines and SQL analysis tools listed in its own README.

What You Get

  • A Parser::parse_sql() entry point that turns SQL text into a Vec of typed AST Statement nodes
  • Built-in Dialect implementations for Postgres, MySQL, Snowflake, BigQuery, ClickHouse, DuckDB, Databricks, Hive, MSSQL, Oracle, Redshift, SQLite, and more, plus a GenericDialect
  • Syntax round-trip via Display/to_string(), recovering the original SQL (modulo comments/whitespace) from the parsed AST
  • Optional visitor feature for recursively walking the AST, and serde feature for serializing AST nodes
  • A Spanned trait for recovering source locations from AST nodes, useful for diagnostics tooling

Common Use Cases

  • Providing the SQL front-end for a query engine or database, as done by Apache DataFusion, Polars, and GlueSQL
  • Building SQL linters, formatters, or migration tools that need to parse, transform, and re-emit SQL
  • Static analysis of SQL queries embedded in application code (e.g. detecting unsafe patterns or unsupported dialect features)
  • Building custom SQL dialects or database proxies (e.g. ParadeDB, CipherStash Proxy, JumpWire) that need to intercept and rewrite SQL

Under The Hood

Architecture - The crate is organized into tokenizer.rs (lexing), parser/ (the Pratt/recursive-descent parser producing the AST), ast/ (the typed AST node definitions and their Display impls for round-tripping), keywords.rs (a large reserved/non-reserved keyword table), and dialect/ (per-database Dialect trait implementations that toggle parsing rules). This separation lets a single tokenizer and core grammar serve dozens of dialects by having each Dialect impl override specific parsing hooks rather than forking the whole parser.

Tech Stack - Nearly pure Rust (99.5% of the repo), zero mandatory external dependencies for the core parser, with optional serde (AST serialization) and recursive (stack-overflow protection on deeply nested queries, on by default via recursive-protection) as the only real feature-gated dependencies. It’s built and released under the Apache Software Foundation’s governance as part of the broader Apache DataFusion project.

Code Quality - Testing is extensive and dialect-segmented: 19+ dedicated test files under tests/ (e.g. sqlparser_postgres.rs, sqlparser_snowflake.rs, sqlparser_clickhouse.rs, sqlparser_regression.rs) plus a sqlparser_bench micro-benchmark suite for tracking parser performance across changes. The project enforces cargo fmt and cargo clippy in CI and requires tests on every PR, per its contributing guidelines — the README states PRs without tests are not reviewed.

API Design - Parser::parse_sql(&dialect, sql) is the entire entry point for the common case, and the crate deliberately avoids semantic analysis so it accepts syntactically valid-but-semantically-wrong SQL (like duplicate column names), keeping it usable as a base for many different downstream semantic layers. Round-trip formatting (ast[0].to_string() reproducing the original SQL) is a notable ergonomic feature for tooling authors who need to both parse and re-emit SQL, though the project is explicit that it does not accept major API-breaking refactors, favoring incremental dialect additions instead.

Used by 5 apps in this directory

TypeScript
69%
Apache 2.0

Laminar

AI Development · Monitoring

3,180

Open-source observability platform purpose-built for AI agents — trace, evaluate, debug, and monitor at scale with SQL access and real-time replay.

View details
85
Repo Health
76
Technical
70
Dependency
Built with
TypeScript69%
Rust29%
Updated yesterday
Go
80%
AGPL 3.0

PeerDB

Data Engineering · Databases

3,241

Postgres-native ETL that streams change data capture in real time to Snowflake, BigQuery, ClickHouse, S3, and Kafka — up to 10x faster than general-purpose pipelines, managed through a familiar Postgres SQL interface.

View details
88
Repo Health
76
Technical
68
Dependency
Built with
Go80%
TypeScript13%
Updated today
Rust
63%
MIT

PostgresML

Databases · AI Development

6,817

Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.

View details
51
Repo Health
76
Technical
65
Dependency
Built with
Rust63%
JavaScript11%
Updated 1 years ago
Rust
31%
Other

Windmill

Automation · Developer Tools

17,577

Turn scripts into webhooks, workflows, and auto-generated UIs — the fastest self-hostable workflow engine, 13x faster than Airflow.

View details
91
Repo Health
82
Technical
66
Dependency
Built with
Rust31%
Svelte22%
TypeScript22%
Updated today
Python
61%
Apache 2.0

WrenAI

Analytics · AI Agents · Data Engineering

17,313

Open-source GenBI engine that lets AI agents turn natural-language questions into governed SQL, charts, and shareable dashboards across 20+ data sources — no vendor lock-in, no black-box prompts.

View details
91
Repo Health
91
Technical
69
Dependency
Built with
Python61%
Rust36%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search