Skip to content

Guide · Open source

How to use sqlfluff: install, lint and auto-fix SQL

Updated · written with AI from the project's own documentation and checked against our catalogue data

SQLFluff is a SQL linter that checks your code for style and layout problems and can fix most of them automatically. This guide is for people who maintain SQL, especially data pipelines and dbt or ELT projects, and want a shared style without reviewing every line by hand. After reading it you will be able to install SQLFluff, lint and fix a file, and pick the right dialect.

SQLFluffsqlfluff/sqlfluff · ★ 10k · MIT

Quick start

  1. 1Install Python. SQLFluff is installed through pip, so you need a working Python environment first.
  2. 2Install SQLFluff. Run pip install sqlfluff to install it from PyPI.
  3. 3Create a test file. Save a SQL file, such as test.sql, that you want to check.
  4. 4Lint the file. Run sqlfluff lint with --dialect set to your database dialect to list issues.
  5. 5Fix the file. Run sqlfluff fix to apply automatic fixes for most problems, then review the changes.
  6. 6Add it to your project. Use the same dialect and templating setup across your team so the style is enforced consistently.

What SQLFluff does

SQLFluff is a dialect-flexible and configurable SQL linter. It checks SQL code for style and layout problems, and it can auto-fix most linting errors. It is designed with ELT applications in mind and also works with Jinja templating and dbt.

It checks code rather than running it, so it is not a way to execute a single query.

Install SQLFluff with pip

The README installs SQLFluff from PyPI with pip. The prerequisite listed is Python. The README also mentions an official Docker image and an online version you can try in a browser.

  • Install from PyPI with pip
  • Optional: install the rs extra for the Rust-backed parser and lexer, which may need a Rust toolchain if no prebuilt wheel exists for your platform
  • Alternative: use the official SQLFluff Docker image or the online version
$ pip install sqlfluff

Lint a SQL file

Create a file and run sqlfluff lint on it. The --dialect flag tells SQLFluff which SQL dialect to check against. The README example uses the ansi dialect. Each reported issue shows its line and position, a rule code such as LT01, a description, and a category tag such as layout.spacing.

  • Use --dialect to match your database, for example ansi in the README example
  • Each line of output names a rule code, so you can look up what it checks in the rules reference
$ echo " SELECT a + b FROM tbl; " > test.sql $ sqlfluff lint test.sql --dialect ansi

Fix SQL files automatically

To apply fixes, run sqlfluff fix instead of lint. The README says SQLFluff will auto-fix most linting errors, so you still need to check the result, especially for rules it cannot fix.

  • Run sqlfluff lint to see problems without changing files
  • Run sqlfluff fix to apply automatic fixes
  • Full CLI options are in the CLI usage docs at docs.sqlfluff.com
$ sqlfluff fix test.sql --dialect ansi

Choose a dialect and templating

SQLFluff supports many dialects, including PostgreSQL, BigQuery, Snowflake, MySQL, DuckDB and SQLite. Support may be partial for some, so check the README list for yours. For templated SQL, SQLFluff supports Jinja, SQL placeholders, Python format strings, and dbt, where dbt requires a plugin.

  • Dialects: check the README list, since support is not always complete
  • Templates: Jinja, SQL placeholders such as SQLAlchemy parameters, Python format strings, and dbt (requires plugin)
  • If your syntax is missing, the README asks you to raise an issue

Use it in your editor

The README links a VS Code extension, maintained in its own repository and published in the VS Code marketplace. Use it if you want feedback while you type.

  • VS Code extension repository: github.com/sqlfluff/vscode-sqlfluff
  • Extension is listed in the VS Code marketplace

What people use it for

  • Keeping dbt models and ELT SQL consistent across a data team
  • Enforcing one shared SQL layout style automatically
  • Checking SQL written for several dialects, such as PostgreSQL and BigQuery, in one workflow
  • Linting Jinja-templated SQL before it reaches a pipeline

Frequently asked questions

How do I install sqlfluff?

The README installs SQLFluff from PyPI with the command pip install sqlfluff. Python is the listed prerequisite. The README also mentions an official Docker image and an online version.

Is sqlfluff free to use?

SQLFluff is released under the MIT licence, as listed in the project details. The MIT licence is permissive, so check its terms for your own use case.

What is the difference between sqlfluff lint and sqlfluff fix?

sqlfluff lint reports style and layout problems without changing your files. sqlfluff fix applies automatic fixes, which the README says can handle most linting errors.

Does sqlfluff support dbt?

Yes. The README says SQLFluff works with dbt and Jinja templating, but dbt support requires a plugin.

Which SQL dialects does sqlfluff support?

The README lists many dialects, including ANSI SQL, BigQuery, PostgreSQL, Snowflake, MySQL, DuckDB, SQLite and T-SQL. The README notes that support may be partial, so check the list for your database.

How does sqlfluff compare to sqlfmt, sqlcheck or sqlglot?

This source does not compare them in detail. SQLFluff focuses on linting and auto-fixing style and layout, with dialect and templating support. Check each project's documentation to see which fits your needs.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

SQLFluff suits data engineers and teams who maintain dbt or ELT SQL and want a shared style enforced automatically, especially across several dialects or Jinja-templated code. If you only need to run a single query, or your database is not on the supported list, look at other tools instead.

Install options & downloads