Freedom251 › SQL Linters and Formatters
sqlfmt

What sqlfmt is
sqlfmt is a free formatter for PostgreSQL SQL, available as a command-line tool and as a browser formatter running through WebAssembly without installation. Its river-aligned style pads clause keywords so they share a column. The CLI can read SQL from files or stdin and write formatted output to stdout; it can also rewrite files in place, list files needing changes, and show unified diffs. The explain subcommand formats PostgreSQL plan text and offers advice, canonicalization, and structural comparison. Its diff operation exits 0 for structurally matching plans and 1 when structures differ, which supports use in scripts and CI. A Go subpackage exposes formatting for Go programs, and the repository includes Emacs and Vim integrations. The WebAssembly build provides formatting and version functions to browser JavaScript. Deeply nested subqueries and less common upsert or DDL forms remain best-effort areas. The project is released under the PostgreSQL Licence.
Who it suits
sqlfmt suits PostgreSQL developers who want consistent SQL formatting in a command line, browser, Go program, or supported editor. Its EXPLAIN tools may also suit people comparing query-plan structure in scripts or CI.
What it does well
- Formats PostgreSQL SQL in browser without installation.
- CLI supports in-place rewriting and unified diffs.
- EXPLAIN tools compare plan structures.
- Includes Emacs and Vim integrations.
- Released under the PostgreSQL Licence.
What to know first
- Supports PostgreSQL only.
- Nested subqueries remain best-effort formatting cases.
- Uncommon upsert or DDL forms remain best-effort.
- WebAssembly builds require tinygo and wasm-opt.
Limits
Deeply nested subqueries and unusual upsert or DDL forms are best-effort formatting cases. The browser formatter is free; no quota or seat limit is stated.
Plans
| Plan | Billed and limits | Price |
|---|---|---|
| Browser formatter | runs in browser via WebAssembly · no install required | Free |
As github.com lists them, read 2 Oct 2026. The maker's own page has the final word.
Getting started
- Open the browser formatter at https://github.com/dimitri/sqlfmt to format SQL without installation.
- Use the command-line tool to format SQL from files or standard input.
- Choose whether to write output to standard output, rewrite files in place, list files needing changes, or show unified diffs.
- Use the explain subcommand to format PostgreSQL plans, request advice, or compare plan structures.
Verdict
sqlfmt provides several ways to format PostgreSQL SQL, plus tools for working with EXPLAIN plans. Its stated best-effort areas matter if your SQL uses deep nesting or less common upsert and DDL forms.
Questions
How much does sqlfmt cost?
It is free. The Browser formatter plan is listed as free.
Which SQL dialect does it support?
PostgreSQL.
Can I use sqlfmt in a browser?
Yes. The browser formatter runs sqlfmt through WebAssembly and requires no installation.
What can the EXPLAIN tools do?
They can format PostgreSQL plan text, provide advice about plan structure, and compare plans. Advice covers join order, join and access methods, and parallelism, without costs, row estimates, or timing.
Is sqlfmt open source, and who makes it?
It is released under the PostgreSQL Licence. Dimitri Fontaine describes himself as a PostgreSQL Major Contributor and the author of The Art of PostgreSQL.
Which editor integrations are included?
The repository provides an Emacs sqlfmt-mode and a Vim integration through formatprg and equalprg.
Facts from sqlfmt's own pages
- Browser use
- The PostgreSQL SQL Formatter runs sqlfmt in a browser through WebAssembly and is free to use without installation. · github.com, 30 Sept 2026
- Build requirements
- Building WebAssembly requires tinygo and wasm-opt on PATH. · github.com, 2 Oct 2026
- Canonicalization
- The -canonical option normalizes ordering and schema-qualification differences when comparing advice from different sources. · github.com, 30 Sept 2026
- CI use
- explain diff exits 0 when plans are structurally identical and 1 when they are not, so it composes into scripts and CI. · github.com, 2 Oct 2026
- CLI input/output
- The command reads SQL from files or stdin and writes formatted SQL to stdout, with options for in-place rewriting, listing differences, and unified diffs. · github.com, 30 Sept 2026
- CLI modes
- The CLI formats files, rewrites files in place, lists files needing changes, shows unified diffs, reads stdin, and prints its version. · github.com, 2 Oct 2026
- Compatibility limits
- Deeply nested subqueries and exotic upsert or DDL forms remain best-effort formatting areas. · github.com, 30 Sept 2026
- Editor integrations
- The repository provides an Emacs sqlfmt-mode and a Vim ftplugin using formatprg and equalprg. · github.com, 2 Oct 2026
- EXPLAIN support
- The explain subcommand formats EXPLAIN output and provides advice, diff, and canonical operations. · github.com, 2 Oct 2026
- EXPLAIN tools
- The explain subcommand formats PostgreSQL plan text and can produce plan advice or structural diffs. · github.com, 30 Sept 2026
- Formatting style
- It implements a river-aligned style in which clause keywords are right-padded to end at the same column. · github.com, 2 Oct 2026
- Go library
- The format subpackage exposes format.Format(io.Reader), but its module path is described as not yet published. · github.com, 2 Oct 2026
- Known limits
- Deeply nested subqueries and exotic upsert or DDL forms remain best-effort. · github.com, 2 Oct 2026
- License
- sqlfmt is distributed under the PostgreSQL Licence. · github.com, 2 Oct 2026
- Maker background
- Dimitri Fontaine describes himself as a PostgreSQL Major Contributor and the author of The Art of PostgreSQL. · theartofpostgresql.com, 30 Sept 2026
- Maker profile
- Dimitri Fontaine identifies as a PostgreSQL Major Contributor and links to support at oss.theartofpostgresql.com. · github.com, 2 Oct 2026
- Plan advice
- The advice output describes join order, join method, access method, and parallelism without costs, row estimates, or timing. · github.com, 2 Oct 2026
- Plan comparison
- Explain diff exits 0 for structurally identical plans and 1 when their structures differ. · github.com, 30 Sept 2026
- Purpose
- sqlfmt is a gofmt-style command-line formatter for PostgreSQL SQL. · github.com, 2 Oct 2026
- Source corpus
- The formatting style was derived from 343 SQL files in The Art of PostgreSQL query corpus. · github.com, 30 Sept 2026
- Target use
- The tool is intended for SQL embedded in The Art of PostgreSQL book and courses and for standalone SQL formatting. · github.com, 2 Oct 2026
- WASM size
- The TinyGo and Binaryen build is around 330KB compared with around 2.9MB for the standard Go WebAssembly target. · github.com, 2 Oct 2026
- WebAssembly API
- The WebAssembly build exposes sqlfmt.format(sql) and sqlfmt.version for browser use. · github.com, 2 Oct 2026
- WebAssembly size
- The TinyGo and wasm-opt build is about 330 KB, compared with about 2.9 MB for the standard Go WebAssembly target. · github.com, 30 Sept 2026
Where sqlfmt stands on Freedom251
- SQL Linters and Formatters#8 of 26