Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

CLI Reference

sql-dialect-fmt [OPTIONS] [PATH ...]

With no paths, or with -, the CLI reads stdin and writes formatted SQL to stdout. Directory arguments are searched recursively for *.sql files while common generated directories such as .git, node_modules, and target are skipped.

Modes

ModeCommandExit behavior
Printsql-dialect-fmt query.sqlformatted SQL on stdout
Writesql-dialect-fmt --write query.sqlrewrites files in place
Checksql-dialect-fmt --check sql/exits 1 if any file would change
Diffsql-dialect-fmt --check --diff sql/prints unified diffs for unformatted files

Options

OptionMeaning
--dialect snowflake|databricksSelect SQL dialect.
--line-width NTarget print width.
--indent-width NSpaces per indent level.
--no-uppercasePreserve keyword casing instead of upper-casing keywords.
--stdin-filepath PATHUse a path for stdin config discovery and diagnostics.
--no-configIgnore sql-dialect-fmt.toml.
--writeRewrite path arguments in place.
--checkVerify formatting without writing.
--diffShow diffs with --check.

Homebrew

brew tap hjosugi/sql-dialect-fmt https://github.com/hjosugi/sql-dialect-fmt
brew install sql-dialect-fmt

CI

- uses: hjosugi/sql-dialect-fmt@v1
  with:
    args: "sql/**/*.sql"
docker run --rm -v "$PWD:/work" -w /work ghcr.io/hjosugi/sql-dialect-fmt:1.18.0 --check .

pre-commit

repos:
  - repo: https://github.com/hjosugi/sql-dialect-fmt
    rev: v1.18.0
    hooks:
      - id: sql-dialect-fmt

Use sql-dialect-fmt-check for verification-only hooks.