pgfmt 2.1: In-Place Formatting and pg_dump-Compatible Output

PostgreSQL · 18 Jun 2026 · 2 min read

#postgresql

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, aliases pgdump, postgres) reproduces the layout of PostgreSQL's ruleutils.c deparser — the same format as pg_get_viewdef and pg_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.

Source: https://www.postgresql.org/about/news/pgfmt-21-in-place-formatting-and-pg_dump-compatible-output-3321/

Related

auto-curated · source linked above ← all news