
SQLFluff
CLI支持二十多种 SQL 方言的 linter 与格式化工具,可自动修复大部分问题,兼容 Jinja 模板与 dbt 项目(dbt 需装插件),适合在数仓代码评审和 CI 中使用。

The SQL Linter for Humans
SQLFluff is a dialect-flexible and configurable SQL linter. Designed with ELT applications in mind, SQLFluff also works with Jinja templating and dbt. SQLFluff will auto-fix most linting errors, allowing you to focus your time on what matters.
Table of Contents
- Dialects Supported
- Templates Supported
- VS Code Extension
- Getting Started
- Documentation
- Releases
- SQLFluff on Slack
- SQLFluff on Twitter
- Contributing
- Sponsors
Dialects Supported
Although SQL is reasonably consistent in its implementations, there are several different dialects available with variations of syntax and grammar. SQLFluff currently supports the following SQL dialects (though perhaps not in full):
- ANSI SQL - this is the base version and on occasion may not strictly follow the ANSI/ISO SQL definition
- Athena
- BigQuery
- ClickHouse
- Databricks (note: this extends the
sparksqldialect with Unity Catalog syntax). - Db2
- Doris
- DuckDB
- Exasol
- FlinkSQL
- Greenplum
- Hive
- Impala
- MariaDB
- Materialize
- MySQL
- Oracle
- PostgreSQL (aka Postgres)
- Redshift
- Snowflake
- SOQL
- SparkSQL
- SQLite
- StarRocks
- Teradata
- Transact-SQL (aka T-SQL)
- Trino
- Vertica
We aim to make it easy to expand on the support of these dialects and also add other, currently unsupported, dialects. Please raise issues (or upvote any existing issues) to let us know of demand for missing support.
Pull requests from those that know the missing syntax or dialects are especially welcomed and are the best way for you to get support added. We are happy to work with any potential contributors on this to help them add this support. Please raise an issue first for any large feature change to ensure it is a good fit for this project before spending time on this work.
Templates Supported
SQL itself does not lend itself well to modularity, so to introduce some flexibility and reusability it is often templated as discussed more in our modularity documentation.
SQLFluff supports the following templates:
- Jinja (aka Jinja2)
- SQL placeholders (e.g. SQLAlchemy parameters)
- Python format strings
- dbt (requires plugin)
Again, please raise issues if you wish to support more templating languages/syntaxes.
VS Code Extension
We also have a VS Code extension:
Getting Started
To get started, install the package and run sqlfluff lint or sqlfluff fix.
$ pip install sqlfluff
$ echo " SELECT a + b FROM tbl; " > test.sql
$ sqlfluff lint test.sql --dialect ansi
== [test.sql] FAIL
L: 1 | P: 1 | LT01 | Expected only single space before 'SELECT' keyword.
| Found ' '. [layout.spacing]
L: 1 | P: 1 | LT02 | First line should not be indented.
| [layout.indent]
L: 1 | P: 1 | LT13 | Files must not begin with newlines or whitespace.
| [layout.start_of_file]
L: 1 | P: 11 | LT01 | Expected only single space before binary operator '+'.
| Found ' '. [layout.spacing]
L: 1 | P: 14 | LT01 | Expected only single space before naked identifier.
| Found ' '. [layout.spacing]
L: 1 | P: 27 | LT01 | Unnecessary trailing whitespace at end of file.
| [layout.spacing]
L: 1 | P: 27 | LT12 | Files must end with a single trailing newline.
| [layout.end_of_file]
All Finished 📜 🎉!
If you want the optional Rust-backed parser and lexer, install the rs extra:
$ pip install sqlfluff[rs]
On supported CPython 3.10+ platforms this installs a prebuilt ABI3 wheel. If no
wheel is published for your platform, pip falls back to building sqlfluffrs
from source, which requires a Rust toolchain and a working C/C++ build setup.
The easiest way to install Rust is with rustup.
Alternatively, you can use the Official SQLFluff Docker Image or have a play using SQLFluff online.
For full CLI usage and rules reference, see the SQLFluff docs.
Documentation
For full documentation visit docs.sqlfluff.com. This documentation is generated from this repository so please raise issues or pull requests for any additions, corrections, or clarifications.
Releases
SQLFluff adheres to Semantic Versioning, so breaking changes should be restricted to major versions releases. Some elements (such as the python API) are in a less stable state and may see more significant changes more often. For details on breaking changes and how to migrate between versions, see our release notes. See the changelog for more details. If you would like to join in, please consider contributing.
New releases are made monthly. For more information, visit Releases.
SQLFluff on Slack
We have a fast-growing community on Slack, come and join us!
SQLFluff on Twitter
Follow us on Twitter @SQLFluff for announcements and other related posts.
Contributing
We are grateful to all our contributors. There is a lot to do in this project, and we are just getting started.
If you want to understand more about the architecture of SQLFluff, you can find more here.
If you would like to contribute, check out the open issues on GitHub. You can also see the guide to contributing, including the pull request acceptance principles and AI-assisted contribution expectations.
Sponsors

The turnkey analytics stack, find out more at Datacoves.com.
相關資源

SQLMesh
CLI用 SQL 或 Python 编写数据转换模型的框架。提供类似 Terraform 的 plan / apply 流程、虚拟数据环境、单元测试和表差异比对,能在 10 多种 SQL 方言之间转译。Linux 基金会项目,可以替代 dbt。
SQLMesh/sqlmesh3.3k
mycli
CLI带智能补全与语法高亮的 MySQL 终端客户端,兼容 MariaDB、TiDB 等;支持 --execute 与批处理模式,可按 CSV 或表格格式输出查询结果,便于 agent 直接执行 SQL。
dbcli/mycli12k
Datasette
CLI把 SQLite 数据库发布成可以浏览、可以查询的网页和 JSON API,支持 SQL 查询、元数据和插件扩展,也能用 datasette publish 部署到 Cloud Run 等平台。适合数据探索和数据新闻,需要 Python 3.10 及以上版本。
simonw/datasette11.5k
sqlite-utils
CLISimon Willison 出品的命令行工具与 Python 库:把 JSON、CSV 直接导入 SQLite 并自动建表,对文件跑内存 SQL 查询,还支持全文检索与表结构变换。
simonw/sqlite-utils2.2k
MySQL MCP Server
MCP让 agent 受控地访问 MySQL:列出库表、查看表结构与样本数据、执行 SQL,支持多库模式、SSL 与 SSH 隧道。需自行配置数据库账号,建议使用最小权限用户。
designcomputer/mysql_mcp_server1.4k
Apache Doris MCP Server
MCPApache Doris 官方 MCP:以只读方式让 agent 探查库表元数据、执行与解释 SQL、诊断慢查询,并查看集群状态、导入任务与数据治理信息。需 Python 3.12+ 与 Doris 2.0 以上。
apache/doris-mcp-server351