1. Home
  2. Tools
  3. SQL Formatter

Format SQL into something a human can review

A 300-line query dumped from a log is unreviewable. This formatter normalises indentation, capitalises keywords, lines up SELECT lists and breaks long JOIN chains across separate lines, without touching your dialect.

Dialects
ANSI, PostgreSQL, MySQL
Keyword casing
Up, down or preserve
Parsing
In-browser
SQL Formatter Only whitespace and keyword casing change

Measured on Apple M4 Max: 0.53 ms format a 120-column query with five joins (120 select expressions) See the benchmarks

How to use it

  1. Paste the query A single statement or a full script with several statements separated by semicolons both work.
  2. Pick a style Choose the indentation width and whether keywords are upper-cased, lower-cased or left exactly as you typed them.
  3. Copy the formatted SQL The output keeps your identifiers, string literals and comments intact — only whitespace and keyword casing are changed.

Reference

Before and after on a typical join

InputOutput
`select o.id,o.total from orders o join customers c on c.id=o.customer_id where o.status='paid' order by o.total desc``SELECT o.id, o.total FROM orders o JOIN customers c ON c.id = o.customer_id WHERE o.status = 'paid' ORDER BY o.total DESC`

A CTE expands onto its own lines

ConstructFormatted result
`WITH recent AS (SELECT * FROM events WHERE created_at > now() - interval '7 days') SELECT count(*) FROM recent`The CTE body is indented one level under `WITH`, and the outer `SELECT` returns to the left margin.

Questions people ask

Will the formatter change my query?

No. It only changes whitespace and, if you ask for it, the casing of SQL keywords. Table names, column names, string literals and comments are left byte-for-byte identical.

Does it support PostgreSQL, MySQL or BigQuery syntax?

It handles the common syntax shared across those dialects, including CTEs, window functions, `INSERT ... ON CONFLICT`, `FILTER` clauses and array literals. Vendor-specific procedural syntax inside a `DO` or `BEGIN` block is preserved but not re-indented.

How do I keep my table and column names lowercase?

Use the "preserve" keyword casing option. Only whitespace and layout are then adjusted, and your identifiers stay exactly as you wrote them.

Can it format a script with several statements?

Yes. Statements separated by semicolons are formatted individually and kept in order.

Does it reformat a stored procedure body?

It preserves the body as a block of text and formats the surrounding statement. Dialect-specific procedural bodies are not re-indented internally because doing so safely requires a full parser for that dialect.

Why is there no "execute" button?

Because there is no server to execute against. The tool never receives a connection string, which is exactly why it is safe to paste a query that points at a production database.

Where this earns its keep

Reviewing a query in a pull request

Formatting both sides of a diff with the same tool makes a real logic change visible. Without it, a reindented query can bury a changed WHERE clause in hundreds of lines of noise.

Reading a query out of application logs

Logged SQL arrives as a single string with no whitespace. Running it through the formatter gives you something you can read in a terminal.

Standardising a legacy codebase

A formatting pass with a fixed style gives a team one canonical shape for every query, which is worth more than it sounds once the diffs start to shrink.

Details that catch people out

Comments and literals are left alone

A `--` comment keeps its text, and a string literal such as `'CASE WHEN'` is not treated as a keyword. That distinction matters: a naive formatter will happily upper-case the word inside your quoted data.

Window functions and CTEs are first-class

The formatter understands `OVER (...)`, `WITH ... AS`, `FILTER (WHERE ...)` and common table expressions, so the indentation reflects real structure instead of just counting parentheses.

Readability is a security property

The most common cause of a production incident in a data pipeline is a WHERE clause that was quietly altered. Reviewing SQL is far easier when every query in the repository has the same shape, and this tool lets you set that shape in one place.

  • Works on SELECT, INSERT, UPDATE, DELETE, DDL and multi-statement scripts.
  • Never modifies string literals or identifiers.
  • Choose 2, 4 or 8 space indentation.
  • Handles CTEs, subqueries, window functions and set operations.

Guides that go deeper

Last reviewed 2026-10-15. Every tool on DevSnap runs entirely in your browser, so whatever you paste here never reaches a server.