sqlfmt

APIyesOSS—FREEyesDOCS5/5
SQ7.4#1 of 26
outWeb—Windows—MacoutLinux—Android—iOS

Ranked in SQL Linters and Formatters ·Free plan

About

sqlfmt is a free formatter for PostgreSQL SQL, available as a command-line tool and a browser formatter that runs through WebAssembly without installation. Its river-aligned style places clause keywords in a shared column. The CLI reads SQL from files or standard input and writes formatted SQL to standard output; options also support in-place rewrites, listing files that need changes and unified diffs. Its explain subcommand formats PostgreSQL plan text and offers advice, canonicalization and structural comparisons. Plan advice describes join order and method, access method and parallelism, without costs, row estimates or timing. Explain diff returns one exit code when plan structures match and another when they differ, which supports scripts and CI use. A Go subpackage exposes formatting to Go programs, and the repository includes Emacs and Vim integrations. The WebAssembly build exposes formatting and version functions to browser JavaScript. Deeply nested subqueries and less common upsert or DDL forms remain best-effort areas. sqlfmt is released under the PostgreSQL Licence.

Who it is for

sqlfmt suits PostgreSQL developers who want consistent formatting in the CLI, browser, Go programs or supported editors. Its EXPLAIN comparison operations may also fit scripts and CI workflows.

What is good

  • Formats PostgreSQL SQL in CLI and browser
  • Supports in-place rewrites and unified diffs
  • Provides EXPLAIN advice and structural comparisons
  • Includes Go, Emacs and Vim integrations
  • Released under the PostgreSQL Licence

What to know first

  • Deeply nested subqueries are best-effort
  • Some upsert and DDL forms are best-effort

Verdict

sqlfmt offers several ways to format PostgreSQL SQL, with plan analysis and structural diffs as additional capabilities. Its best-effort handling of deeply nested and less common SQL forms is worth considering for the code it will process.

Compared on SQL linters and formatters

Free plan
Yesgithub.com
Supported SQL dialects
PostgreSQLgithub.com
Automatic fixes
Yesgithub.com
Editor extensions
Yesgithub.com
CI/CD integration
Yesgithub.com

Facts

Purpose
sqlfmt is a gofmt-style command-line formatter for PostgreSQL SQL.github.com · 30 Sept 2026
Formatting style
It implements a river-aligned style that right-pads clause keywords to the same column.github.com · 30 Sept 2026
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
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
EXPLAIN tools
The explain subcommand formats PostgreSQL plan text and can produce plan advice or structural diffs.github.com · 30 Sept 2026
Plan comparison
Explain diff exits 0 for structurally identical plans and 1 when their structures differ.github.com · 30 Sept 2026
Canonicalization
The -canonical option normalizes ordering and schema-qualification differences when comparing advice from different sources.github.com · 30 Sept 2026
Go library
The format subpackage exposes Format(io.Reader) (string, error) for formatting SQL in Go programs.github.com · 30 Sept 2026
Editor integrations
The repository provides an Emacs sqlfmt-mode and Vim ftplugin integration through formatprg and equalprg.github.com · 30 Sept 2026
WebAssembly API
The WebAssembly build exposes sqlfmt.format(sql) and sqlfmt.version to browser JavaScript.github.com · 30 Sept 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
Compatibility limits
Deeply nested subqueries and exotic upsert or DDL forms remain best-effort formatting areas.github.com · 30 Sept 2026
Source corpus
The formatting style was derived from 343 SQL files in The Art of PostgreSQL query corpus.github.com · 30 Sept 2026
License
sqlfmt is released under the PostgreSQL Licence.github.com · 30 Sept 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
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
EXPLAIN support
The explain subcommand formats EXPLAIN output and provides advice, diff, and canonical operations.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
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
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
Build requirements
Building WebAssembly requires tinygo and wasm-opt on PATH.github.com · 2 Oct 2026
Known limits
Deeply nested subqueries and exotic upsert or DDL forms remain best-effort.github.com · 2 Oct 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
Maker profile
Dimitri Fontaine identifies as a PostgreSQL Major Contributor and links to support at oss.theartofpostgresql.com.github.com · 2 Oct 2026

Best sqlfmt alternatives

See all 20

Where it ranks on Inferse

Sources