← 返回命令列表

Linux command

sqlfluff 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Lint

sqlfluff lint --dialect [postgres] [path/to/query.sql]

Auto-fix

sqlfluff fix --dialect [bigquery] [path/to/queries/]

Format

cat [query.sql] | sqlfluff format --dialect [snowflake] -

Show parsed token tree

sqlfluff parse --dialect [mysql] [query.sql]

Lint only specific rules

sqlfluff lint --rules [LT01,LT02,CP01] [path/to/file.sql]

Exclude noisy rules

sqlfluff lint --exclude-rules [L034,L036] [path/to/file.sql]

Generate a starter

sqlfluff render --dialect [ansi] [query.sql]

说明

sqlfluff is a dialect-aware linter and auto-formatter for SQL. It parses queries into an abstract syntax tree, applies a configurable set of rules, and reports or rewrites violations. Unlike text-based linters, the AST approach lets it enforce structural rules such as comma placement, keyword casing, ambiguous joins, and column-reference qualification. The tool supports a wide range of dialects (PostgreSQL, MySQL, BigQuery, Snowflake, Redshift, T-SQL, SQLite, DuckDB, Databricks, ANSI, and more) and integrates with templating engines so it can lint queries written in Jinja, dbt, or custom placeholder syntaxes without first rendering them. Operation is split into commands: lint reports violations, fix rewrites the source in place, format applies layout-only fixes, parse dumps the token tree, and render expands templating without linting. Configuration is layered: built-in defaults are overridden by .sqlfluff files discovered up the directory tree, pyproject.toml sections, then command-line flags.

参数

--dialect _NAME_
SQL dialect to parse against (e.g. ansi, postgres, mysql, bigquery, snowflake, redshift, tsql, sqlite, duckdb, databricks). Run sqlfluff dialects for the full list.
--templater _NAME_
Templating engine to use before parsing: raw, jinja, python, placeholder, or dbt.
--rules _LIST_
Comma-separated list of rules (or rule groups) to enable.
--exclude-rules _LIST_
Comma-separated list of rules to skip.
-f, --force
For fix: apply changes without asking for confirmation.
--FIX-EVEN-UNPARSABLE
Allow fix to operate on files with templating or parse errors (dangerous).
--processes _N_
Number of parallel workers; 0 means all CPUs, negative means cpus + N.
-v, -vv, -vvv
Increase verbosity; stackable.
--nocolor
Disable ANSI color in output.
--format _FMT_
Output format: human, json, yaml, github-annotation, github-annotation-native.
--config _FILE_
Path to an explicit .sqlfluff configuration file.
--encoding _ENC_
File encoding to use when reading sources (default autodetect).
--disable-noqa
Ignore -- noqa: comments embedded in SQL.

FAQ

What is the sqlfluff command used for?

sqlfluff is a dialect-aware linter and auto-formatter for SQL. It parses queries into an abstract syntax tree, applies a configurable set of rules, and reports or rewrites violations. Unlike text-based linters, the AST approach lets it enforce structural rules such as comma placement, keyword casing, ambiguous joins, and column-reference qualification. The tool supports a wide range of dialects (PostgreSQL, MySQL, BigQuery, Snowflake, Redshift, T-SQL, SQLite, DuckDB, Databricks, ANSI, and more) and integrates with templating engines so it can lint queries written in Jinja, dbt, or custom placeholder syntaxes without first rendering them. Operation is split into commands: lint reports violations, fix rewrites the source in place, format applies layout-only fixes, parse dumps the token tree, and render expands templating without linting. Configuration is layered: built-in defaults are overridden by .sqlfluff files discovered up the directory tree, pyproject.toml sections, then command-line flags.

How do I run a basic sqlfluff example?

Run `sqlfluff lint --dialect [postgres] [path/to/query.sql]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --dialect _NAME_ do in sqlfluff?

SQL dialect to parse against (e.g. ansi, postgres, mysql, bigquery, snowflake, redshift, tsql, sqlite, duckdb, databricks). Run sqlfluff dialects for the full list.