PostgreSQL Formatter
Format PostgreSQL queries with indentation, keyword casing, and line breaks tuned for the PostgreSQL dialect. Paste compact or messy SQL and get a clean, readable layout. All formatting runs in your browser.
Formatting runs entirely in your browser.
How it works
The tool uses the sql-formatter library, a dialect-aware SQL pretty-printer that runs entirely in your browser. It parses your query and re-emits it with consistent indentation and capitalisation.
Example
Input
insert into t (a) values (1) returning idFormatted
INSERT INTO
t (a)
VALUES
(1)
RETURNING
idProcessing runs in your browser
All formatting happens locally in your browser tab. Our servers are not involved at any point.
Related operations
For inspecting JSON returned by queries, try the JSON formatter. To validate identifier patterns in your SQL, use the regex tester. For converting query results into structured rows, see CSV to JSON.
Frequently asked questions
- Which PostgreSQL features does the formatter handle?
- Standard SQL plus PostgreSQL-specific syntax: RETURNING clauses, JSONB operators, double-quoted identifiers, CTEs, window functions, and dollar-quoted strings used in functions.
- Does the formatter validate PostgreSQL syntax?
- The formatter does not fully validate SQL; it only adjusts whitespace and capitalisation. If it cannot parse your query, it shows an error with the line and column where parsing failed instead of formatted output.
- Can I format CTEs and window functions?
- Yes. The formatter aligns WITH clauses, OVER() expressions, and PARTITION BY/ORDER BY for readability.
- How are dollar-quoted function bodies formatted?
- A $$ ... $$ function body is kept exactly as you wrote it, as one string, so PL/pgSQL code inside it is left intact but not re-indented. Queries outside dollar quotes format as usual.
Last reviewed September 30, 2026
Other pages for this tool
Related tools
- Background reading: Complete guide to developer tools