SQLFormatter
FormatterConvertPricingDocsGet Pro
Formatter & beautifier · PostgreSQL

Format & beautify PostgreSQL SQL online

Format and beautify PostgreSQL SQL: consistent indentation, aligned clauses, uppercase keywords — and minified one-liners expanded back into readable code.

1Paste your PostgreSQL query into the editor.
2Press Format — or ⌘↵.
3Copy clean, highlighted SQL.
Open formatter
before
select u.id,u.email,u.data->>'plan' as plan from users u where u.data->>'active'='true' and u.email ilike '%@acme.com' order by u.created_at desc limit 25;
PostgreSQL
SELECT
  u.id,
  u.email,
  u.data ->> 'plan' AS plan
FROM
  users u
WHERE
  u.data ->> 'active' = 'true'
  AND u.email ILIKE '%@acme.com'
ORDER BY
  u.created_at DESC
LIMIT
  25;

Why format PostgreSQL?

PostgreSQL adds syntax no generic beautifier handles cleanly: the JSONB accessors -> and ->>, :: casts, ILIKE, RETURNING clauses and array literals. The formatter parses against Postgres grammar so these stay intact instead of being mangled into keywords.

It also keeps dollar-quoted strings ($$ … $$) and CTEs structurally correct — the exact constructs that make hand-formatting Postgres tedious.

Beautify minified PostgreSQL SQL

Minified Postgres — CTEs and subqueries crushed onto one line by an ORM or a copy-paste from psql — becomes unreadable fast. Beautifying it puts each CTE, JOIN and clause on its own indented line so the query's shape is visible again.

That readable layout is what makes a query reviewable: a clean, multi-line Postgres query produces a sane git diff, so teammates can actually see what changed in a pull request.

minified
WITH t AS(SELECT user_id,sum(amount)total FROM payments WHERE status='paid' GROUP BY user_id)SELECT u.email,t.total FROM users u JOIN t ON t.user_id=u.id WHERE t.total>1000 ORDER BY t.total DESC;
PostgreSQL · beautified
WITH
  t AS (
    SELECT
      user_id,
      sum(amount) total
    FROM
      payments
    WHERE
      status = 'paid'
    GROUP BY
      user_id
  )
SELECT
  u.email,
  t.total
FROM
  users u
  JOIN t ON t.user_id = u.id
WHERE
  t.total > 1000
ORDER BY
  t.total DESC;

Frequently asked questions

Does the formatter understand PostgreSQL-specific syntax?

Yes. The query is parsed against PostgreSQL grammar rather than generic SQL, so PostgreSQL-only constructs survive formatting: JSONB operators, :: casts, ILIKE and RETURNING.

What is the difference between formatting and beautifying PostgreSQL SQL?

Nothing — they are two names for the same operation. "Format" usually describes tidying SQL you wrote yourself; "beautify" usually describes expanding a minified or ORM-generated one-liner into readable lines. This page does both, with a worked example of each above.

Is my SQL uploaded anywhere?

No. Formatting runs entirely in your browser — the query never leaves your machine and nothing is stored on a server.

Is the PostgreSQL formatter free?

Yes: free, no account, no usage limit. Only the optional AI features — explain, optimize and dialect conversion — require signing in.

All SQL formatters & beautifiers

Format PostgreSQLFormat MySQLFormat T-SQLFormat SQLiteFormat BigQueryFormat OracleFormat SnowflakeFormat Redshift