PostgreSQL Formatter
Beautify Postgres queries, including :: casts, JSONB operators, CTEs and RETURNING clauses.
SQL
Formatted SQL
Your SQL is processed in this browser tab and never uploaded.
How to use the PostgreSQL Formatter
- Paste your PostgreSQL query into the editor, or press Sample to load an example.
- The PostgreSQL dialect is already selected, so dialect-specific syntax is parsed correctly.
- Press Format (Ctrl + Enter). Pick indentation and keyword case in the options.
- Copy the result or download it as a .sql file.
Example
Input
with recent as (select id, payload->>'email' as email, created_at::date as day from events where payload @> '{"type":"signup"}') insert into signups (email, day) select email, day from recent on conflict (email) do nothing returning id;PostgreSQL syntax this formatter understands
- Type casts written with :: (for example created_at::date) stay attached to their expression.
- JSON and JSONB operators such as ->, ->>, #> and @> are kept intact.
- Dollar-quoted function bodies ($$ ... $$ or $tag$ ... $tag$) are treated as a single literal and are not reformatted.
- Common table expressions (WITH ... AS), RETURNING, ON CONFLICT and FILTER clauses get their own lines.
What it does
- PostgreSQL-aware parsing
- Uses the PostgreSQL grammar from the open-source sql-formatter library, so syntax that is specific to PostgreSQL is handled correctly.
- Keyword case control
- Keep the original case, or convert all keywords to UPPERCASE or lowercase as you format.
- Private by design
- Formatting happens on your device. Nothing you paste leaves the browser.
Frequently asked questions
Is my PostgreSQL query sent to a server?
No. The formatter runs entirely in your browser. Your query is never uploaded, logged or stored, so it is safe to paste production SQL.
Will formatting change what my query does?
No. Only whitespace, line breaks and (if you choose) keyword case change. String literals, quoted identifiers and comments are kept exactly as written.
Does it validate my query?
The formatter has to parse your query, so badly broken SQL produces an error with its location. It does not check that tables or columns exist, and some invalid queries still format.