dfmt
Grammar-driven SQL formatting for 15 dialects with native dbt/Jinja support.
dfmt parses SQL into a full AST using the same grammar-driven parser that powers column lineage and type inference, then pretty-prints it using Wadler's algorithm. This means it understands SQL structure deeply -- not just tokens.
Key Features
- 15 SQL dialects: ANSI, BigQuery, PostgreSQL, DuckDB, Snowflake, Spark, Databricks, Oracle, DB2, T-SQL, MariaDB, Presto, Trino, Redshift, SQLite
- Native dbt/Jinja: Evaluates Jinja templates, formats the SQL, and restores Jinja constructs -- not regex-based
- Idempotent:
format(format(x)) == format(x)-- always - Fast: ~2s for 3,500 dbt models (parallel JVM)
- CI-ready:
--checkmode exits 1 if any file needs formatting - Configurable: keyword case, comma style, alignment, line width, and more via
.dfmt.json
Quick Start
# Create a config file
dfmt --init snowflake
# Format all SQL files
dfmt --write
# Check formatting in CI
dfmt --check
# Format files changed since main
dfmt --changed-since main --write
See Getting Started for installation and setup, or CLI Reference for the full flag list.