PostgreSQL SQL Formatter

Paste a PostgreSQL query to pretty-print it with 2 spaces, 4 spaces or tabs, or minify it. The dialect is already set to PostgreSQL, so dollar-quotes, RETURNING and DISTINCT ON stay intact. Keyword case can be upper, lower or preserve. Schema names and literals never leave this tab.

Input
Output
Waiting for Format or Minify

Runs in this tab · nothing is uploaded · Verify in 10 seconds →

What this does

This page is the SQL Formatter locked to the PostgreSQL dialect, so dollar-quotes, RETURNING, DISTINCT ON and interval literals are recognised as keywords and not broken across lines. Pick keyword case and indent, then press Format. Queries stay in this tab.

PostgreSQL is the dialect most production logs use for JSON, arrays and CTEs. Formatting does not change identifiers or string literals, including spaces inside 'Ada Lovelace' and bodies inside $$ … $$. Only whitespace and, if you ask, keyword case change.

When it goes wrong

A friendly parse error means the dialect could not read the statement: usually an unclosed quote, an unclosed /* comment or a dollar-quote tag that never closes. The first line of the error is shown; fix that and format again.

When to use this

Beautify a query copied from pgAdmin, a slow-query log or an EXPLAIN plan before you paste it into a review or a ticket.

This page is a focused view of theSQL Formatter & Beautifier, which has the full set of options.

Frequently asked questions

Does this upload my SQL?

No. Formatting loads the formatter library in this tab. Schema names and customer literals never leave the device.

How is this different from Standard SQL?

The PostgreSQL dialect recognises Postgres-only syntax such as dollar-quoting, RETURNING and DISTINCT ON so those tokens are not split or lowercased incorrectly.

Can I switch to MySQL or SQL Server?

Yes. The dialect picker is still on the toolbar, or open the full SQL Formatter for every dialect.

Does formatting change literals?

No. String literals, comments and dollar-quoted bodies stay as written.

What does Minify do?

It collapses insignificant whitespace while leaving strings and comments byte-for-byte, useful for a single log line.

Which keyword case should I pick?

Upper is the common house style for SQL keywords. Preserve keeps whatever you pasted. Lower is used by some codebases.