DBDelve
Dive deep into your data. A fast, native, multi-engine database client written in Rust. Free and open source, no telemetry.
翻訳待ち
Python SQL Parser and Transpiler
翻訳待ち
開発ツールPython · MakefileGitHub @tobymao自分でインストール所有者未確認
Paste into Claude or ChatGPT for installation instructions suited to your environment.
Have you tried it? One tap is enough. No sign-in needed.
No updates detected yet. GitHub releases will appear here.
Loading the full README. The saved excerpt is shown below.
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.Read the full README ↗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!
From PyPI:
# 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
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.We'd love to hear from you. Join our community Slack channel!
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 queries that a real engine would reject. SQLGlot is a transpiler, not a validator. A query that parses successfully may still fail at execution time.
Why doesn't the output preserve my formatting, casing or quoting?
SQLGlot parses queries into an AST and generates SQL back from it, so it preserves the meaning of a query rather than its exact text. Cosmetic details can change in the process. Use pretty=True for formatted output and identify=True to quote all identifiers. Comments are preserved on a best-effort basis.
How can I make parsing faster?
Install the version compiled with mypyc: pip3 install "sqlglot[c]". It is roughly 3-5x faster than the pure Python version (see Benchmarks).
My dialect isn't supported. What are my options?
You can subclass an existing dialect (Custom Dialects), or ship one as a separate package (Creating a Dialect Plugin). Keep in mind that subclassing may not work properly with sqlglot[c] installed, so custom dialects may require the pure Python version.
Easily translate from one dialect to another. For example, date/time functions vary between dialects and can be hard to deal with:
import sqlglot
sqlglot.transpile("SELECT EPOCH_MS(1618088028295)", read="duckdb", write="hive")[0]
'SELECT FROM_UNIXTIME(1618088028295 / POW(10, 3))'
SQLGlot can even translate custom time formats:
import sqlglot
sqlglot.transpile("SELECT STRFTIME(x, '%y-%-m-%S')", read="duckdb", write="hive")[0]
"SELECT DATE_FORMAT(x, 'yy-M-ss')"
Identifier delimiters and data types can be translated as well:
This is the beginning of the README. Read the rest at the original. Read the full README ↗