All Tools
T

SQL Formatter

Format SQL queries locally with dialect-aware whitespace rules.

Read the full guide for this tool
SQL Formatter only adjusts whitespace and layout for the selected dialect. It is not a semantic validator, and output may normalize casing, line breaks, and spacing. Editing the SQL or changing any formatting option clears the current result until you format again.

SQL Formatter: Clean Up Queries Without Leaving the Browser

You pasted a query from logs and it came through as one unreadable line. Or you are reviewing a migration with nested subqueries, mixed keyword casing, and joins stacked together with no visual structure. An SQL formatter fixes the presentation so you can read the query again.

This tool acts as an SQL beautifier for day-to-day developer work. Paste a statement, format it, and copy back a cleaner version with consistent indentation, spacing, and line breaks. If you need to format SQL online without installing an editor plugin or CLI package, this is the fast path.

It runs entirely in the browser, so formatting stays local to your machine. That matters when the SQL includes internal table names, customer-specific schemas, or query fragments copied from production debugging.

If you change the SQL or adjust the dialect, keyword casing, or indentation, the current formatted output clears until you run the formatter again.

Using it

Paste your SQL into the input, run the formatter, review the output, and copy the result. For example, a dense query like select u.id,u.email,o.total from users u join orders o on o.user_id=u.id where o.status='paid' order by o.created_at desc; becomes much easier to scan once each clause gets its own line.

Use it when you want to pretty print SQL before reviewing a query, saving a snippet, or sharing it in chat, docs, or a pull request. It is especially useful for long SELECT lists, multi-table joins, CASE expressions, and CTE-heavy reporting queries.

What formatting helps with

Formatting does not change query semantics, but it does change how quickly you can reason about the statement.

For example, compare a compressed CTE with a formatted one:

with recent_orders as (select user_id,sum(total) as revenue from orders where created_at >= current_date - interval '30 days' group by user_id) select u.email,r.revenue from users u join recent_orders r on r.user_id = u.id order by r.revenue desc;

Once formatted, the CTE, aggregation, join, and ordering stop fighting for the same line length.

SQL formatter vs SQL validation

An SQL formatter rewrites whitespace and layout. It does not prove the query is correct.

That distinction matters. A formatter cannot tell you whether:

SELECT * FROM missing_table; can be perfectly formatted and still fail immediately in Postgres or MySQL. Formatting is about readability, not execution.

Dialect differences matter

Most SQL shares the same broad structure, but a Postgres SQL formatter and a MySQL SQL formatter still have to deal with real differences in quoting, functions, and dialect-specific syntax.

Postgres queries often include constructs like ILIKE, RETURNING, DISTINCT ON, ::uuid, JSON operators such as ->>, and interval expressions like interval '7 days'. MySQL code more often uses backticks, LIMIT 10, 20, INSERT ... ON DUPLICATE KEY UPDATE, and functions such as IFNULL() or DATE_FORMAT().

Formatting helps you read both styles, but it does not translate between them. If you paste MySQL syntax into a Postgres codebase, a formatter can make it prettier, not portable.

When this tool is useful

Troubleshooting

Why does the SQL formatter fail on my query? — Most formatters still need input they can tokenize reliably. Broken quotes, incomplete comments, pasted shell prompts, or truncated SQL from logs can prevent formatting.

Does formatting validate that my SQL is correct? — No. It improves readability only. It does not validate schema names, execution plans, permissions, transaction safety, or runtime behavior.

Will this work as a Postgres SQL formatter and MySQL SQL formatter? — It can format many common statements from both dialects, but formatting support is not the same thing as full engine-level parsing or compatibility.

Why did keyword casing change? — SQL beautifiers often normalize keywords like select, from, and join for consistency. That is a presentation change, not a semantic one.

Can I safely paste sensitive queries here? — The tool runs in the browser, so formatting happens locally rather than on a server. You should still use normal judgment around secrets embedded directly in SQL text.