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
| Mode | Command | Exit behavior |
|---|---|---|
sql-dialect-fmt query.sql | formatted SQL on stdout | |
| Write | sql-dialect-fmt --write query.sql | rewrites files in place |
| Check | sql-dialect-fmt --check sql/ | exits 1 if any file would change |
| Diff | sql-dialect-fmt --check --diff sql/ | prints unified diffs for unformatted files |
Options
| Option | Meaning |
|---|---|
--dialect snowflake|databricks | Select SQL dialect. |
--line-width N | Target print width. |
--indent-width N | Spaces per indent level. |
--keyword-case upper|lower|preserve | Choose recognized keyword casing. |
--select-item-layout auto|vertical | Keep short SELECT lists inline or put one item per line. |
--comma-style trailing|leading | Place commas at the end or start of wrapped list lines. |
--line-ending auto|lf|crlf | Preserve or select output line endings. |
--no-uppercase | Deprecated shorthand for preserving keyword casing. |
--stdin-filepath PATH | Use a path for stdin config discovery and diagnostics. |
--no-config | Ignore sql-dialect-fmt.toml. |
--write | Rewrite path arguments in place. |
--check | Verify formatting without writing. |
--diff | Show 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.22.3 --check .
pre-commit
repos:
- repo: https://github.com/hjosugi/sql-dialect-fmt
rev: v1.22.3
hooks:
- id: sql-dialect-fmt
Use sql-dialect-fmt-check for verification-only hooks.