使用 SQLGlot 在不同方言间转换和验证 SQL
Use SQLGlot when an agent needs to parse, transpile, or sanity-check SQL before moving queries between engines or trusting generated SQL.
Prerequisites
Python 3.8+, SQLGlot, and any agent or script that needs SQL parsing, transpilation, or validation.
Installation
Use the upstream install or setup path that matches your environment:
- # Optionally prefix with UV=1 to use uv for the installation
- make install
- make install-dev
- make docs-serve
Requirements and caveats from upstream:
- It is a very comprehensive generic SQL parser with a robust test suite. It is also quite performant, while being written purely in Python.
- # Pure python version
- Like parsing, generating SQL also requires the target dialect to be specified, otherwise the SQLGlot dialect will be used by default. For example, to transpile a query from Spark SQL to DuckDB, do parse_one(sql, diale...
Basic usage or getting-started notes:
- 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...
- Run Tests and Lint
- From PyPI:
- Source: https://github.com/1991513ccie-png/skills
- Extracted from upstream docs: https://raw.githubusercontent.com/tobymao/sqlglot/HEAD/README.md
Documentation
- https://sqlglot.com/sqlglot.html