SQL Formatter
Useful on the single-line queries that come out of an application log or pg_stat_statements, where the structure is the thing you actually need to see.
Scope
This is a formatter, not a parser. It breaks on the major clause keywords, indents subqueries and
parenthesised lists, and puts each item in a SELECT list on its own
line. It deliberately does not rewrite your query, reorder anything, or validate syntax — a
formatter that changes semantics is worse than none.
String literals, quoted identifiers, and comments are protected before formatting and restored afterwards, so a keyword inside a string is left alone. Dialect-specific syntax that leans on unusual quoting may still come out oddly — check the result before running it anywhere that matters.
To find out what a query does rather than how it reads, format it here and then put it
through EXPLAIN (ANALYZE, BUFFERS). The plan is the thing that
answers the question.