+2
Daily
9,790
stars
1,413
forks
49
watchers
5,738
prs
3,146
issues
0
releases
README
!SQLGlot logo
SQLGlot is a no-dependency SQL parser, transpiler, optimizer, and engine. It can be used to format SQL or translate between over 30 dialects like DuckDB, Presto / Trino, Spark / Databricks, Snowflake, and BigQuery. It aims to read a wide variety of SQL inputs and output syntactically and semantically correct SQL in the targeted dialects.
It is a very comprehensive generic SQL parser with a robust test suite. It is also quite performant, while being written purely in Python.
You can easily customize the parser, analyze queries, traverse expression trees, and programmatically build SQL.
SQLGlot can detect a variety of syntax errors, such as unbalanced parentheses, incorrect usage of reserved keywords, and so on. These errors are highlighted and dialect incompatibilities can warn or raise depending on configurations.
Learn more about SQLGlot in the API documentation and the expression tree primer.
Contributions are very welcome in SQLGlot; read the contribution guide and the onboarding document to get started!
Table of Contents
Install
Versioning
Get in Touch
FAQ
Examples
Formatting and Transpiling
Metadata
Parser Errors
Unsupported Errors
Build and Modify SQL
SQL Optimizer
AST Introspection
AST Diff
Custom Dialects
SQL Execution
Used By
Documentation
Run Tests and Lint
Benchmarks
Optional Dependencies
Supported Dialects
Install
From PyPI:
bash
Pure python version
pip3 install sqlglot
C extensions compiled with mypyc (Python 3.10+)
prebuilt wheel if available for your platform, otherwise builds from source
pip3 install "sqlglot[c]"
On Python 3.9, sqlglot[c] installs the pure Python version.
Or with a local checkout:
Optionally prefix with UV=1 to use uv for the installation
make install
Requirements for development (optional):
Optionally prefix with UV=1 to use uv for the installation
make install-dev
Versioning
Given a version number MAJOR.MINOR.PATCH:
- PATCH is incremented for backwards-compatible changes.
- MINOR is incremented for backwards-incompatible changes.
- MAJOR is incremented for significant backwards-incompatible changes.
Get in Touch
We'd love to hear from you. Join our community Slack channel!
FAQ
I tried to parse SQL that should be valid, but it failed. Why?
You probably didn't specify the source dialect. Without it, parse_one assumes the "SQLGlot dialect", which is designed to be a superset of all supported dialects. Always pass the dialect when you know it, e.g. parse_one(sql, dialect="spark"). If parsing still fails, please file an issue.
The generated SQL is not in the correct dialect!
The target dialect must also be specified explicitly. For example, to transpile a query from Spark SQL to DuckDB, do parse_one(sql, dialect="spark").sql(dialect="duckdb"), or transpile(sql, read="spark", write="duckdb").
Why does SQLGlot parse my invalid SQL without complaining?
The parser is intentionally lenient, so it can accept queriesTop issues
#9102TSQL: CAST(x AS BOOLEAN) in a predicate generates invalid SQL on the first transpile pass1 comments · 2026-11-14#9083Snowflake to Spark: DATEADD/TIMESTAMPADD with HOUR, MINUTE or SECOND becomes day-based DATE_ADD1 comments · 2026-11-13#9006optimize_joins: comma join rewritten to CROSS JOIN changes join grouping, wrong rows with RIGHT/FULL JOIN1 comments · 2026-11-11#9114SQLite: bitwise XOR is generated as a ^ b, which SQLite can't parse0 comments · 2026-11-15#9113SQLite: CAST(x AS JSON) is generated verbatim, which SQLite evaluates as a numeric cast0 comments · 2026-11-15#9112DuckDB: printf-style FORMAT from BigQuery/Spark/SQLite/Postgres is written as DuckDB FORMAT, which uses {} placeholders0 comments · 2026-11-15#9107Optimizer drops parentheses for `NOT (<date> = DATE_TRUNC(...))`, changing query results0 comments · 2026-11-15#9104BigQuery: region-qualified INFORMATION_SCHEMA reference is rewritten across transpile passes, gaining an invented alias0 comments · 2026-11-14