About the SQL formatter
Long SQL queries are hard to read when they arrive on a single line from a log, an ORM or a colleague's message. A SQL formatter puts each clause, such as SELECT, FROM, JOIN, WHERE and GROUP BY, on its own line and indents the rest, so the structure of the query is easy to follow and review.
This formatter understands 20 SQL dialects, including MySQL, PostgreSQL, SQL Server, SQLite, Oracle, BigQuery, Snowflake, ClickHouse and DuckDB. It can also minify a query onto a single line, and lets you choose keyword, function and data type case, indentation and where AND/OR go.
How to use the SQL formatter
- Paste one or more SQL statements into the Input editor, or click Load sample.
- Choose your database in the Dialect menu. The tool remembers it for your next visit in this browser.
- Choose Format for readable SQL or Minify for a single line, then pick a keyword case and indentation. Open More options for function case, data type case and AND/OR placement.
- Click Format SQL (or Minify SQL) or press Ctrl + Enter (Cmd + Enter on Mac), then click Copy result.
Examples
Format a one-line query
Input
select u.id, u.email, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = true and o.created_at > '2026-01-01' group by u.id, u.email order by orders desc limit 10;Output
SELECT
u.id,
u.email,
count(o.id) AS orders
FROM
users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE
u.active = TRUE
AND o.created_at > '2026-01-01'
GROUP BY
u.id,
u.email
ORDER BY
orders DESC
LIMIT
10;Keyword case set to upper.
Minify a query for a log or a code string
Input
SELECT id,
email
FROM users
WHERE active = true;Output
SELECT id,email FROM users WHERE active = TRUE;Common errors and how to fix them
Parse error: Unexpected "[id] FROM " at line 1 column 8.
The query uses another database's syntax, like SQL Server's [brackets], MySQL's backticks or PostgreSQL's :: casts. Pick the matching dialect from the menu.
Parse error: Unexpected "{{id}}" at line 1 column 33.
Placeholders from your code aren't SQL. Replace them with ?, $1 or :id parameters, which the formatter understands.
Comments disappear after minifying
Minify removes comments on purpose. If a comment carries a query hint, keep that query formatted instead.
Good to know
- Pick the dialect that matches your database. Syntax such as
$1placeholders (PostgreSQL),@idvariables and[bracketed]names (SQL Server) or backtick quotes (MySQL) depends on it, and the wrong dialect can cause a parse error. - When formatting, comments (
--and/* */) are kept and multiple statements separated by;get a blank line between them. - Minify first checks the query with the parser, then removes comments and extra whitespace. Text inside strings and quoted names, such as
'--not a comment', PostgreSQL$$…$$blocks and SQL Server[bracketed]names, is left exactly as it is. - The formatter only changes layout and letter case. It doesn't check whether tables or columns exist, and it never runs your query.
- The SQL parser loads the first time you click Format SQL, so the first run can take a moment.
Frequently asked questions
Why do I get a parse error?
Usually the query uses syntax from another database. Switch the Dialect to the database you use. An unfinished query, such as a missing closing bracket, also causes a parse error, and the message shows where.
Should SQL keywords be uppercase?
SQL itself doesn't care about case. Uppercase keywords are a common convention because they stand out from table and column names, but follow whatever style your team uses.
Does formatting change what my query does?
No. Only whitespace, line breaks and keyword case change. String values, identifiers and the logic of the query stay exactly the same.