EVERYTHING XIAOMI
Get listed

sqlfmt

sqlfmt is a PostgreSQL SQL formatter available as a command-line tool and as a browser formatter that runs through WebAssembly without installation.

Place
#3 of 26
Score
6.7
sqlfmt's website

What sqlfmt is

sqlfmt is a PostgreSQL SQL formatter available as a command-line tool and as 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; it can also rewrite files in place, list files that need changes, and show unified diffs. For PostgreSQL EXPLAIN output, its explain subcommand can format plans, describe join order and methods, access methods, and parallelism, or compare plan structure. The diff operation returns different exit codes for matching and differing structures, making it usable in scripts and CI. A Go subpackage provides formatting for Go programs, and the project 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 are best-effort areas. sqlfmt is free and released under the PostgreSQL Licence.

Good

  • Free browser formatter requires no installation.
  • Reads from files or standard input.
  • Can rewrite files and show unified diffs.
  • EXPLAIN diff can compare plan structures.
  • Emacs and Vim integrations are provided.

Watch out

  • Supports PostgreSQL SQL only.
  • Nested subqueries and exotic upsert or DDL are best-effort.
  • WebAssembly builds require tinygo and wasm-opt on PATH.

Who it suits

It suits PostgreSQL users who want consistent SQL formatting in a CLI, browser, Go program, or supported editor. Its EXPLAIN tools may also suit teams comparing plan structure in scripts or CI.

Verdict

sqlfmt combines PostgreSQL formatting with file-diff workflows, editor integrations, and EXPLAIN plan utilities. Expect less complete formatting for deeply nested queries and uncommon upsert or DDL forms.

Plans and prices

From sqlfmt's own pricing page, checked 2 Oct 2001.

All about pricing
PlanPriceWhat it gives you
Browser formatterFreeruns in browser via WebAssembly · no install required

The facts

Each one read from sqlfmt's own pages, with the date it was checked.

Where it runs

Browser use
The PostgreSQL SQL Formatter runs sqlfmt in a browser through WebAssembly and is free to use without installation.checked 30 Sep 2001

What it does

Build requirements
Building WebAssembly requires tinygo and wasm-opt on PATH.checked 2 Oct 2001
Canonicalization
The -canonical option normalizes ordering and schema-qualification differences when comparing advice from different sources.checked 30 Sep 2001
CI use
explain diff exits 0 when plans are structurally identical and 1 when they are not, so it composes into scripts and CI.checked 2 Oct 2001
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.checked 30 Sep 2001
CLI modes
The CLI formats files, rewrites files in place, lists files needing changes, shows unified diffs, reads stdin, and prints its version.checked 2 Oct 2001
Compatibility limits
Deeply nested subqueries and exotic upsert or DDL forms remain best-effort formatting areas.checked 30 Sep 2001
Editor integrations
The repository provides an Emacs sqlfmt-mode and a Vim ftplugin using formatprg and equalprg.checked 2 Oct 2001
EXPLAIN support
The explain subcommand formats EXPLAIN output and provides advice, diff, and canonical operations.checked 2 Oct 2001
EXPLAIN tools
The explain subcommand formats PostgreSQL plan text and can produce plan advice or structural diffs.checked 30 Sep 2001
Formatting style
It implements a river-aligned style in which clause keywords are right-padded to end at the same column.checked 2 Oct 2001
Go library
The format subpackage exposes format.Format(io.Reader), but its module path is described as not yet published.checked 2 Oct 2001
Known limits
Deeply nested subqueries and exotic upsert or DDL forms remain best-effort.checked 2 Oct 2001
License
sqlfmt is distributed under the PostgreSQL Licence.checked 2 Oct 2001
Purpose
sqlfmt is a gofmt-style command-line formatter for PostgreSQL SQL.checked 2 Oct 2001
Source corpus
The formatting style was derived from 343 SQL files in The Art of PostgreSQL query corpus.checked 30 Sep 2001
Target use
The tool is intended for SQL embedded in The Art of PostgreSQL book and courses and for standalone SQL formatting.checked 2 Oct 2001
WASM size
The TinyGo and Binaryen build is around 330KB compared with around 2.9MB for the standard Go WebAssembly target.checked 2 Oct 2001
WebAssembly API
The WebAssembly build exposes sqlfmt.format(sql) and sqlfmt.version for browser use.checked 2 Oct 2001
WebAssembly size
The TinyGo and wasm-opt build is about 330 KB, compared with about 2.9 MB for the standard Go WebAssembly target.checked 30 Sep 2001

The company

Maker background
Dimitri Fontaine describes himself as a PostgreSQL Major Contributor and the author of The Art of PostgreSQL.checked 30 Sep 2001
Maker profile
Dimitri Fontaine identifies as a PostgreSQL Major Contributor and links to support at oss.theartofpostgresql.com.checked 2 Oct 2001

Money

Plan advice
The advice output describes join order, join method, access method, and parallelism without costs, row estimates, or timing.checked 2 Oct 2001
Plan comparison
Explain diff exits 0 for structurally identical plans and 1 when their structures differ.checked 30 Sep 2001

Alternatives to sqlfmt

All alternatives
  1. 1

    Poor SQL

    Free planOpen sourceWebAPIExtensionLinux
    7.3Free plan
  2. 2

    SQLFormat.org

    Free planOpen sourceWebAPIExtensionSelf-hosted
    7.1Free plan
  3. 3

    RegSQL

    Free planWeb
    6.5From $8 a month
  4. 4

    SQLCheck

    Free planLinuxmacOSWindows
    6.5Free plan
  5. 5

    sqlfmt

    Free planWebAPI
    6.5From $9 a month
  6. 6SQLFluff logo

    SQLFluff

    Free planAPILinuxmacOSSelf-hosted
    6.4Free plan