English | 日本語
sql-dialect-fmt
English | 日本語
sql-dialect-fmt is an opinionated Rust formatter and editor toolchain for Snowflake SQL and Databricks SQL. It follows the gofmt / Prettier / Biome style: few options, stable output, and formatting that is safe to run in CI.
Formatting is mechanically lossless and idempotent. Inputs that cannot be parsed pass through unchanged, significant tokens and comments are preserved, and format(format(x)) == format(x).
Install
# From crates.io
cargo install sql-dialect-fmt --version 1.20.0 --locked
# Directly from this repository
cargo install --git https://github.com/hjosugi/sql-dialect-fmt sql-dialect-fmt
# From a local checkout
cargo install --path crates/sql-dialect-fmt-cli
# Binary install, when using release assets with cargo-binstall
cargo binstall sql-dialect-fmt
brew tap hjosugi/sql-dialect-fmt https://github.com/hjosugi/sql-dialect-fmt brew install sql-dialect-fmt
CI can use the bundled composite action or the GHCR image.
- 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.20.0 --check .
Try the browser playground from the docs site:
<https://hjosugi.github.io/sql-dialect-fmt/playground.html>
## Usage
sql-dialect-fmt query.sql # format to stdout sql-dialect-fmt --write .sql # rewrite files in place sql-dialect-fmt --check src//.sql # non-zero when files are not formatted sql-dialect-fmt --check --diff query.sql # show a unified diff for unformatted input sql-dialect-fmt --lint src/ # lint (SDF001-SDF007): path:line:col findings, exit 1 when any cat query.sql | sql-dialect-fmt # stdin to stdout cat query.sql | sql-dialect-fmt - # explicitly read stdin with - sql-dialect-fmt --stdin-filepath src/query.sql < query.sql # use a path for config discovery cat query.sql | sql-dialect-fmt --range 40:120 # reformat only statements in a byte range (stdin)
Options: --dialect snowflake|databricks / --line-width N / --indent-width N / --no-uppercase
pre-commit users can enable the official hooks:
repos: