pgFormatter is a free formatter for PostgreSQL SQL queries and PL/pgSQL code, with support for several SQL standards and PostgreSQL-specific keywords. The project says it also works with other databases. Formatting controls cover keyword, function, identifier, and type case, along with indentation, query wrapping, and comma placement. The command-line `--anonymize` option obscures query literals before formatting. It can run as a console program or as a CGI application that produces text or HTML; a CGI request with an `Accept: application/json` header can return JSON, although the API can be disabled in configuration. The online demo limits SQL queries to ten thousand characters. Installation instructions cover a GitHub source tarball, and the project also documents Docker use, Vim and (Neo)Vim, links to Atom and Visual Studio Code integrations, and a pre-commit hook for SQL files. For other databases, custom lists can cover functions and keywords it cannot detect automatically. pgFormatter is free software distributed under the PostgreSQL Licence.
Who it is for
pgFormatter suits developers who want to format PostgreSQL queries or PL/pgSQL code from a console, CGI setup, editor, or pre-commit workflow. It can also be configured for other databases using custom lists.
What is good
- Free software under the PostgreSQL Licence.
- Offers case, indentation, wrapping, and comma controls.
- Can obscure query literals before formatting.
- Supports console, CGI, and JSON responses.
- Documents editor and pre-commit integrations.
What to know first
- Online demo limits queries to ten thousand characters.
- Other-database functions and keywords need custom lists.
Verdict
pgFormatter offers configurable SQL formatting through console and CGI use, with editor and pre-commit options. The online demo has a query-length limit, and other databases may require custom function or keyword lists.
pgFormatter plans and pricing
All plansCompared on code formatting tools
- Free plan
- Yes


