CLI Reference

sqlfluff

SQLFluff is a modular SQL linter for humans.

sqlfluff [OPTIONS] COMMAND [ARGS]...

Options

--version

Show the version and exit.

Examples:

sqlfluff lint –dialect postgres .

sqlfluff lint –dialect postgres –rules ST05 .

sqlfluff fix –dialect sqlite –rules LT10,ST05 src/queries

sqlfluff parse –dialect sqlite –templater jinja src/queries/common.sql

dialects

Show the current dialects available.

sqlfluff dialects [OPTIONS]

Options

-n, --nocolor

No color - output will be without ANSI color codes.

-v, --verbose

Verbosity, how detailed should the output be. This is stackable, so -vv is more verbose than -v. For the most verbose option try -vvvv or -vvvvv.

--version

Show the version and exit.

fix

Fix SQL files.

PATH is the path to a sql file or directory to lint. This can be either a file (‘path/to/file.sql’), a path (‘directory/of/sql/files’), a single (‘-‘) character to indicate reading from stdin or a dot/blank (‘.’/’ ‘) which will be interpreted like passing the current working directory as a path argument.

sqlfluff fix [OPTIONS] [PATHS]...

Options

-n, --nocolor

No color - output will be without ANSI color codes.

-v, --verbose

Verbosity, how detailed should the output be. This is stackable, so -vv is more verbose than -v. For the most verbose option try -vvvv or -vvvvv.

--version

Show the version and exit.

--stdin-filename <stdin_filename>

When using stdin as an input, load the configuration as if the contents of stdin was in a file in the listed location. This is useful for some editors that pass file contents from the editor that might not match the content on disk.

--library-path <library_path>

Override the library_path value from the [sqlfluff:templater:jinja] configuration value. Set this to ‘none’ to disable entirely. This overrides any values set by users in configuration files or inline directives.

--disable-noqa-except <disable_noqa_except>

Ignore all but the listed rules inline noqa comments.

--disable-noqa

Set this flag to ignore inline noqa comments.

--logger <logger>

Choose to limit the logging to one of the loggers.

Options:

templater | lexer | parser | linter | rules | config

--bench

Set this flag to engage the benchmarking tool output.

-i, --ignore <ignore>

Ignore particular families of errors so that they don’t cause a failed run. For example –ignore parsing would mean that any parsing errors are ignored and don’t influence the success or fail of a run. –ignore behaves somewhat like noqa comments, except it applies globally. Multiple options are possible if comma separated: e.g. –ignore parsing,templating.

--encoding <encoding>

Specify encoding to use when reading and writing files. Defaults to autodetect.

--ignore-local-config

Ignore config files in default search path locations. This option allows the user to lint with the default config or can be used in conjunction with –config to only reference the custom config file.

--config <extra_config_path>

Include additional config file. By default the config is generated from the standard configuration files described in the documentation. This argument allows you to specify an additional configuration file that overrides the standard configuration files. N.B. cfg format is required.

-e, --exclude-rules <exclude_rules>

Exclude specific rules. For example specifying –exclude-rules LT01 will remove rule LT01 (Unnecessary trailing whitespace) from the set of considered rules. This could either be the allowlist, or the general set if there is no specific allowlist. Multiple rules can be specified with commas e.g. –exclude-rules LT01,LT02 will exclude violations of rule LT01 and rule LT02.

-r, --rules <rules>

Narrow the search to only specific rules. For example specifying –rules LT01 will only search for rule LT01 (Unnecessary trailing whitespace). Multiple rules can be specified with commas e.g. –rules LT01,LT02 will specify only looking for violations of rule LT01 and rule LT02.

-t, --templater <templater>

The templater to use (default=jinja)

Options:

raw | jinja | python | placeholder

-d, --dialect <dialect>

The dialect of SQL to lint

--warn-unused-ignores

Warn about unneeded ‘– noqa:’ comments.

--persist-timing <persist_timing>

A filename to persist the timing information for a linting run to in csv format for external analysis. NOTE: This feature should be treated as beta, and the format of the csv file may change in future releases without warning.

--disable-progress-bar

Disables progress bars.

-p, --processes <processes>

The number of parallel processes to run. Positive numbers work as expected. Zero and negative numbers will work as number_of_cpus - number. e.g -1 means all cpus except one. 0 means all cpus.

-f, --force

[DEPRECATED - From 3.0 onward this is the default behaviour] Apply fixes will also be applied file by file, during the linting process, rather than waiting until all files are linted before fixing.

--check

Analyse all files and ask for confirmation before applying any fixes. Fixes will be applied all together at the end of the operation.

-q, --quiet

Reduces the amount of output to stdout to a minimal level. This is effectively the opposite of -v. NOTE: It will only take effect if -f/–force is also set.

-x, --fixed-suffix <fixed_suffix>

An optional suffix to add to fixed files.

--FIX-EVEN-UNPARSABLE

Enables fixing of files that have templating or parse errors. Note that the similar-sounding ‘–ignore’ or ‘noqa’ features merely prevent errors from being displayed. For safety reasons, the ‘fix’command will not make any fixes in files that have templating or parse errors unless ‘–FIX-EVEN-UNPARSABLE’ is enabled on the command lineor in the .sqlfluff config file.

--show-lint-violations

Show lint violations

Arguments

PATHS

Optional argument(s)

format

Autoformat SQL files.

This 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.

PATH is the path to a sql file or directory to lint. This can be either a file (‘path/to/file.sql’), a path (‘directory/of/sql/files’), a single (‘-‘) character to indicate reading from stdin or a dot/blank (‘.’/’ ‘) which will be interpreted like passing the current working directory as a path argument.

sqlfluff format [OPTIONS] [PATHS]...

Options

-n, --nocolor

No color - output will be without ANSI color codes.

-v, --verbose

Verbosity, how detailed should the output be. This is stackable, so -vv is more verbose than -v. For the most verbose option try -vvvv or -vvvvv.

--version

Show the version and exit.

--stdin-filename <stdin_filename>

When using stdin as an input, load the configuration as if the contents of stdin was in a file in the listed location. This is useful for some editors that pass file contents from the editor that might not match the content on disk.

--library-path <library_path>

Override the library_path value from the [sqlfluff:templater:jinja] configuration value. Set this to ‘none’ to disable entirely. This overrides any values set by users in configuration files or inline directives.

--disable-noqa-except <disable_noqa_except>

Ignore all but the listed rules inline noqa comments.

--disable-noqa

Set this flag to ignore inline noqa comments.

--logger <logger>

Choose to limit the logging to one of the loggers.

Options:

templater | lexer | parser | linter | rules | config

--bench

Set this flag to engage the benchmarking tool output.

-i, --ignore <ignore>

Ignore particular families of errors so that they don’t cause a failed run. For example –ignore parsing would mean that any parsing errors are ignored and don’t influence the success or fail of a run. –ignore behaves somewhat like noqa comments, except it applies globally. Multiple options are possible if comma separated: e.g. –ignore parsing,templating.

--encoding <encoding>

Specify encoding to use when reading and writing files. Defaults to autodetect.

--ignore-local-config

Ignore config files in default search path locations. This option allows the user to lint with the default config or can be used in conjunction with –config to only reference the custom config file.

--config <extra_config_path>

Include additional config file. By default the config is generated from the standard configuration files described in the documentation. This argument allows you to specify an additional configuration file that overrides the standard configuration files. N.B. cfg format is required.

-e, --exclude-rules <exclude_rules>

Exclude specific rules. For example specifying –exclude-rules LT01 will remove rule LT01 (Unnecessary trailing whitespace) from the set of considered rules. This could either be the allowlist, or the general set if there is no specific allowlist. Multiple rules can be specified with commas e.g. –exclude-rules LT01,LT02 will exclude violations of rule LT01 and rule LT02.

-r, --rules <rules>

Narrow the search to only specific rules. For example specifying –rules LT01 will only search for rule LT01 (Unnecessary trailing whitespace). Multiple rules can be specified with commas e.g. –rules LT01,LT02 will specify only looking for violations of rule LT01 and rule LT02.

-t, --templater <templater>

The templater to use (default=jinja)

Options:

raw | jinja | python | placeholder

-d, --dialect <dialect>

The dialect of SQL to lint

--warn-unused-ignores

Warn about unneeded ‘– noqa:’ comments.

--persist-timing <persist_timing>

A filename to persist the timing information for a linting run to in csv format for external analysis. NOTE: This feature should be treated as beta, and the format of the csv file may change in future releases without warning.

--disable-progress-bar

Disables progress bars.

-p, --processes <processes>

The number of parallel processes to run. Positive numbers work as expected. Zero and negative numbers will work as number_of_cpus - number. e.g -1 means all cpus except one. 0 means all cpus.

-x, --fixed-suffix <fixed_suffix>

An optional suffix to add to fixed files.

Arguments

PATHS

Optional argument(s)

lint

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

PATH is the path to a sql file or directory to lint. This can be either a file (‘path/to/file.sql’), a path (‘directory/of/sql/files’), a single (‘-‘) character to indicate reading from stdin or a dot/blank (‘.’/’ ‘) which will be interpreted like passing the current working directory as a path argument.

Linting SQL files:

sqlfluff lint path/to/file.sql sqlfluff lint directory/of/sql/files

Linting a file via stdin (note the lone ‘-’ character):

cat path/to/file.sql | sqlfluff lint - echo ‘select col from tbl’ | sqlfluff lint -

sqlfluff lint [OPTIONS] [PATHS]...

Options

-n, --nocolor

No color - output will be without ANSI color codes.

-v, --verbose

Verbosity, how detailed should the output be. This is stackable, so -vv is more verbose than -v. For the most verbose option try -vvvv or -vvvvv.

--version

Show the version and exit.

--stdin-filename <stdin_filename>

When using stdin as an input, load the configuration as if the contents of stdin was in a file in the listed location. This is useful for some editors that pass file contents from the editor that might not match the content on disk.

--library-path <library_path>

Override the library_path value from the [sqlfluff:templater:jinja] configuration value. Set this to ‘none’ to disable entirely. This overrides any values set by users in configuration files or inline directives.

--disable-noqa-except <disable_noqa_except>

Ignore all but the listed rules inline noqa comments.

--disable-noqa

Set this flag to ignore inline noqa comments.

--logger <logger>

Choose to limit the logging to one of the loggers.

Options:

templater | lexer | parser | linter | rules | config

--bench

Set this flag to engage the benchmarking tool output.

-i, --ignore <ignore>

Ignore particular families of errors so that they don’t cause a failed run. For example –ignore parsing would mean that any parsing errors are ignored and don’t influence the success or fail of a run. –ignore behaves somewhat like noqa comments, except it applies globally. Multiple options are possible if comma separated: e.g. –ignore parsing,templating.

--encoding <encoding>

Specify encoding to use when reading and writing files. Defaults to autodetect.

--ignore-local-config

Ignore config files in default search path locations. This option allows the user to lint with the default config or can be used in conjunction with –config to only reference the custom config file.

--config <extra_config_path>

Include additional config file. By default the config is generated from the standard configuration files described in the documentation. This argument allows you to specify an additional configuration file that overrides the standard configuration files. N.B. cfg format is required.

-e, --exclude-rules <exclude_rules>

Exclude specific rules. For example specifying –exclude-rules LT01 will remove rule LT01 (Unnecessary trailing whitespace) from the set of considered rules. This could either be the allowlist, or the general set if there is no specific allowlist. Multiple rules can be specified with commas e.g. –exclude-rules LT01,LT02 will exclude violations of rule LT01 and rule LT02.

-r, --rules <rules>

Narrow the search to only specific rules. For example specifying –rules LT01 will only search for rule LT01 (Unnecessary trailing whitespace). Multiple rules can be specified with commas e.g. –rules LT01,LT02 will specify only looking for violations of rule LT01 and rule LT02.

-t, --templater <templater>

The templater to use (default=jinja)

Options:

raw | jinja | python | placeholder

-d, --dialect <dialect>

The dialect of SQL to lint

--warn-unused-ignores

Warn about unneeded ‘– noqa:’ comments.

--persist-timing <persist_timing>

A filename to persist the timing information for a linting run to in csv format for external analysis. NOTE: This feature should be treated as beta, and the format of the csv file may change in future releases without warning.

--disable-progress-bar

Disables progress bars.

-p, --processes <processes>

The number of parallel processes to run. Positive numbers work as expected. Zero and negative numbers will work as number_of_cpus - number. e.g -1 means all cpus except one. 0 means all cpus.

-f, --format <format>

What format to return the lint result in (default=human).

Options:

human | json | yaml | github-annotation | github-annotation-native | none

--write-output <write_output>

Optionally provide a filename to write the results to, mostly used in tandem with –format. NB: Setting an output file re-enables normal stdout logging.

--annotation-level <annotation_level>

When format is set to “github-annotation” or “github-annotation-native”, default annotation level (default=”warning”). “failure” and “error” are equivalent. Any rules configured only as warnings will always come through with type “notice” regardless of this option.

Options:

notice | warning | failure | error

--nofail

If set, the exit code will always be zero, regardless of violations found. This is potentially useful during rollout.

--disregard-sqlfluffignores

Perform the operation regardless of .sqlfluffignore configurations

Arguments

PATHS

Optional argument(s)

parse

Parse SQL files and just spit out the result.

PATH is the path to a sql file or directory to lint. This can be either a file (‘path/to/file.sql’), a path (‘directory/of/sql/files’), a single (‘-‘) character to indicate reading from stdin or a dot/blank (‘.’/’ ‘) which will be interpreted like passing the current working directory as a path argument.

sqlfluff parse [OPTIONS] PATH

Options

-n, --nocolor

No color - output will be without ANSI color codes.

-v, --verbose

Verbosity, how detailed should the output be. This is stackable, so -vv is more verbose than -v. For the most verbose option try -vvvv or -vvvvv.

--version

Show the version and exit.

--stdin-filename <stdin_filename>

When using stdin as an input, load the configuration as if the contents of stdin was in a file in the listed location. This is useful for some editors that pass file contents from the editor that might not match the content on disk.

--library-path <library_path>

Override the library_path value from the [sqlfluff:templater:jinja] configuration value. Set this to ‘none’ to disable entirely. This overrides any values set by users in configuration files or inline directives.

--disable-noqa-except <disable_noqa_except>

Ignore all but the listed rules inline noqa comments.

--disable-noqa

Set this flag to ignore inline noqa comments.

--logger <logger>

Choose to limit the logging to one of the loggers.

Options:

templater | lexer | parser | linter | rules | config

--bench

Set this flag to engage the benchmarking tool output.

-i, --ignore <ignore>

Ignore particular families of errors so that they don’t cause a failed run. For example –ignore parsing would mean that any parsing errors are ignored and don’t influence the success or fail of a run. –ignore behaves somewhat like noqa comments, except it applies globally. Multiple options are possible if comma separated: e.g. –ignore parsing,templating.

--encoding <encoding>

Specify encoding to use when reading and writing files. Defaults to autodetect.

--ignore-local-config

Ignore config files in default search path locations. This option allows the user to lint with the default config or can be used in conjunction with –config to only reference the custom config file.

--config <extra_config_path>

Include additional config file. By default the config is generated from the standard configuration files described in the documentation. This argument allows you to specify an additional configuration file that overrides the standard configuration files. N.B. cfg format is required.

-e, --exclude-rules <exclude_rules>

Exclude specific rules. For example specifying –exclude-rules LT01 will remove rule LT01 (Unnecessary trailing whitespace) from the set of considered rules. This could either be the allowlist, or the general set if there is no specific allowlist. Multiple rules can be specified with commas e.g. –exclude-rules LT01,LT02 will exclude violations of rule LT01 and rule LT02.

-r, --rules <rules>

Narrow the search to only specific rules. For example specifying –rules LT01 will only search for rule LT01 (Unnecessary trailing whitespace). Multiple rules can be specified with commas e.g. –rules LT01,LT02 will specify only looking for violations of rule LT01 and rule LT02.

-t, --templater <templater>

The templater to use (default=jinja)

Options:

raw | jinja | python | placeholder

-d, --dialect <dialect>

The dialect of SQL to lint

-c, --code-only

Output only the code elements of the parse tree.

-m, --include-meta

Include meta segments (indents, dedents and placeholders) in the output. This only applies when outputting json or yaml.

-f, --format <format>

What format to return the parse result in.

Options:

human | json | yaml | none

--write-output <write_output>

Optionally provide a filename to write the results to, mostly used in tandem with –format. NB: Setting an output file re-enables normal stdout logging.

--parse-statistics

Set this flag to enabled detailed debugging readout on the use of terminators in the parser.

--nofail

If set, the exit code will always be zero, regardless of violations found. This is potentially useful during rollout.

Arguments

PATH

Required argument

render

Render SQL files and just spit out the result.

PATH is the path to a sql file. This should be either a single file file (‘path/to/file.sql’) or a single (‘-’) character to indicate reading from stdin.

sqlfluff render [OPTIONS] PATH

Options

-n, --nocolor

No color - output will be without ANSI color codes.

-v, --verbose

Verbosity, how detailed should the output be. This is stackable, so -vv is more verbose than -v. For the most verbose option try -vvvv or -vvvvv.

--version

Show the version and exit.

--stdin-filename <stdin_filename>

When using stdin as an input, load the configuration as if the contents of stdin was in a file in the listed location. This is useful for some editors that pass file contents from the editor that might not match the content on disk.

--library-path <library_path>

Override the library_path value from the [sqlfluff:templater:jinja] configuration value. Set this to ‘none’ to disable entirely. This overrides any values set by users in configuration files or inline directives.

--disable-noqa-except <disable_noqa_except>

Ignore all but the listed rules inline noqa comments.

--disable-noqa

Set this flag to ignore inline noqa comments.

--logger <logger>

Choose to limit the logging to one of the loggers.

Options:

templater | lexer | parser | linter | rules | config

--bench

Set this flag to engage the benchmarking tool output.

-i, --ignore <ignore>

Ignore particular families of errors so that they don’t cause a failed run. For example –ignore parsing would mean that any parsing errors are ignored and don’t influence the success or fail of a run. –ignore behaves somewhat like noqa comments, except it applies globally. Multiple options are possible if comma separated: e.g. –ignore parsing,templating.

--encoding <encoding>

Specify encoding to use when reading and writing files. Defaults to autodetect.

--ignore-local-config

Ignore config files in default search path locations. This option allows the user to lint with the default config or can be used in conjunction with –config to only reference the custom config file.

--config <extra_config_path>

Include additional config file. By default the config is generated from the standard configuration files described in the documentation. This argument allows you to specify an additional configuration file that overrides the standard configuration files. N.B. cfg format is required.

-e, --exclude-rules <exclude_rules>

Exclude specific rules. For example specifying –exclude-rules LT01 will remove rule LT01 (Unnecessary trailing whitespace) from the set of considered rules. This could either be the allowlist, or the general set if there is no specific allowlist. Multiple rules can be specified with commas e.g. –exclude-rules LT01,LT02 will exclude violations of rule LT01 and rule LT02.

-r, --rules <rules>

Narrow the search to only specific rules. For example specifying –rules LT01 will only search for rule LT01 (Unnecessary trailing whitespace). Multiple rules can be specified with commas e.g. –rules LT01,LT02 will specify only looking for violations of rule LT01 and rule LT02.

-t, --templater <templater>

The templater to use (default=jinja)

Options:

raw | jinja | python | placeholder

-d, --dialect <dialect>

The dialect of SQL to lint

Arguments

PATH

Required argument

rules

Show the current rules in use.

sqlfluff rules [OPTIONS]

Options

-n, --nocolor

No color - output will be without ANSI color codes.

-v, --verbose

Verbosity, how detailed should the output be. This is stackable, so -vv is more verbose than -v. For the most verbose option try -vvvv or -vvvvv.

--version

Show the version and exit.

version

Show the version of sqlfluff.

sqlfluff version [OPTIONS]

Options

-n, --nocolor

No color - output will be without ANSI color codes.

-v, --verbose

Verbosity, how detailed should the output be. This is stackable, so -vv is more verbose than -v. For the most verbose option try -vvvv or -vvvvv.

--version

Show the version and exit.