How to use the SQL formatter
- Paste a query from your code, a log file or a database console. Several statements separated by semicolons are fine.
- The formatted version appears on the right as you type.
- Choose whether keywords are uppercased, and pick 2 spaces, 4 spaces or tabs.
- Switch to “One line” to collapse a query for a log message, a code string or a chat message.
- Copy the result or download it as a .sql file.
How the formatter decides where lines break
The query is first split into tokens: words, numbers, operators, strings, quoted identifiers and comments. The formatter then applies a small set of layout rules, the same ones many teams use in code review:
Worked example
This one-line query from an application log is hard to scan:
select o.id, c.name, o.total from orders o join customers c on c.id = o.customer_id where o.total > 100 and o.status = 'shipped' order by o.total desc
Formatted, it becomes 12 lines:
SELECT o.id, c.name, o.total FROM orders o JOIN customers c ON c.id = o.customer_id WHERE o.total > 100 AND o.status = 'shipped' ORDER BY o.total DESC
Each filter now sits on its own line, so it is easy to see that the query keeps only shipped orders over 100.
Why formatting matters for SQL
SQL is usually written once and read many times: in code review, while debugging a slow query, or when someone new inherits a report. One condition per line makes mistakes visible, such as an OR that should have been wrapped in brackets with the AND next to it. Version control also benefits, because adding a column changes one line instead of rewriting a long one.
The formatter does not check that the SQL is valid or run it. Text inside quotes, including words like “from” or “select”, is never touched.
Common table expressions
Queries that start with WITH define named sub-queries, called CTEs, before the main SELECT. The formatter indents each CTE body one level deeper and closes it on its own line, so you can read a complex report from top to bottom like a series of steps. Load the sample to see one.
Key features
- Works with standard SQL as used by MySQL, PostgreSQL, SQL Server, SQLite, Oracle and BigQuery.
- Uppercase keywords or keep your own capitalisation.
- Indented sub-queries, CTEs and JOIN conditions.
- One-line compact mode that also removes comments.
- Your queries and table names stay in your browser.
Practical use cases
Reading ORM output. Frameworks such as Django, Rails, Laravel and Hibernate log long generated queries. Paste one here to see the joins and filters clearly.
Code review. Format queries before committing so reviewers see a clean diff.
Sharing with colleagues. Use compact mode to paste a query into a ticket or chat, and formatted mode when you need someone to check its logic.