pgfmt 2.1, the command-line SQL formatter, brings two major features: in-place formatting and pg_dump-compatible output. It is now installable via a Homebrew tap (brew tap gmr/pgfmt && brew install pgfmt), while cargo install pgfmt and prebuilt binaries remain available.
- In-place formatting (
--inplace/-i) writes formatted output directly back to the source file, preserving original file permissions. Works with multiple files:pgfmt -i query1.sql query2.sql. - pg_dump style (
--style pg_dump, aliasespgdump,postgres) reproduces the layout of PostgreSQL'sruleutils.cdeparser — the same format aspg_get_viewdefandpg_get_functiondef. On genuine deparser output, it is byte-idempotent: formatting a catalog dump yields identical bytes, enabling reliable diffing of migrations against actual stored definitions. - Expanded formatting coverage across SQL and PL/pgSQL fixed several correctness bugs, including previously dropped typed string literals (e.g.,
INTERVAL '2 days'). Catalog-dumped views and functions that once failed now format cleanly. - See the release notes for full details.
For developers, the --style pg_dump feature is a game-changer: it ensures the formatted output matches what PostgreSQL itself produces, making it ideal for version-controlling database schemas and validating migration scripts. Combined with in-place editing, pgfmt 2.1 streamlines the workflow of maintaining consistent SQL formatting across a codebase.