SQLFluff Reference

Kip Landergren

(Updated: )

Contents

Selected Commands and Options

sqlfluff lint

Lint SQL files via passing a list of files or using stdin.

Usage:

sqlfluff lint [OPTIONS] [PATHS]...
sqlfluff lint path/to/file.sql
sqlfluff lint --dialect postgres path/to/file.sql
sqlfluff lint directory/of/sql/files

Options:

-d --dialect TEXT the dialect of SQL to lint

sqlfluff fix

Fix SQL files.

Usage:

sqlfluff fix [OPTIONS] [PATHS]...
sqlfluff fix path/to/file.sql
sqlfluff fix --dialect postgres path/to/file.sql
sqlfluff fix directory/of/sql/files

Options:

-d --dialect TEXT the dialect of SQL to lint

Frequently Asked Questions (FAQs)

What is the difference between sqlfluff format and sqlfluff fix?

From the CLI reference :

[sqlfluff format] effectively force applies sqlfluff fix with a known subset of fairly stable rules. Enabled rules are ignored, but rule exclusions (via CLI) or config are still respected.

I do not know the rationale behind making sqlfluff format ignore enabled rules.

How to get a CREATE TABLE statement’s columns laid out correctly?

To achieve a layout like:

CREATE TABLE t_entity_category (
  entity_category_id serial PRIMARY KEY
  , title            text   NOT NULL DEFAULT ''
);

Consider using:

[sqlfluff:layout:type:comma]
line_position = leading

[sqlfluff:layout:type:column]
spacing_before = align
align_scope = file
align_within = statement

[sqlfluff:layout:type:column_definition]
spacing_before = align
align_scope = file
align_within = statement

[sqlfluff:layout:type:column_constraint_segment]
spacing_before = align
align_scope = file
align_within = statement

[sqlfluff:layout:type:data_type]
spacing_before = align
align_scope = file
align_within = statement

Note: as of 2025 Mar I do not see types like column_definition or column_constraint_segment described in the Layout & Whitespace Configuration documentation, the section Configuring layout and spacing mentions:

The syntax of the section headings here select by type, which corresponds to the type defined in the dialect.

Which lead me to:

which describe them.

If alignment is not working correctly, try looking up what sqlfluff marks the type as and configuring its layout.

How to customize the layout of different types?

[sqlfluff:layout:type:data_type]
spacing_before = align
align_scope = file
align_within = statement

How do I make multiple conditions each on their own line?

I have not found that this is possible.

I want it for something like the following set of where conditions:

SELECT
  edge_id
  , node_id
FROM
  edge
WHERE
  is_archived = FALSE AND is_deleted = FALSE AND is_confirmed = TRUE

to be automatically formatted, each on their own new line, to:

SELECT
  edge_id
  , node_id
FROM
  edge
WHERE
  is_archived = FALSE
  AND is_deleted = FALSE
  AND is_confirmed = TRUE

Resources