SQL Formatter
Format and minify SQL queries instantly with dialect support for MySQL, PostgreSQL, and SQLite.
Recent Queries
Your recent queries will appear here
How to use
Paste a SQL query, choose a dialect, then click Format for readable output or Minify for compact SQL. Use Clear to reset and Copy to copy the result.
What is a SQL formatter?
A SQL formatter rewrites a query so that it is easy to read: each clause (SELECT, FROM,
WHERE, JOIN, GROUP BY, ORDER BY) starts on its own line, nested parts are indented and
keywords are written consistently. The query itself does not change; only the whitespace and the
layout do.
Formatted SQL is easier to review in a pull request, to debug when a query returns the wrong rows, and to paste into documentation. Minifying does the opposite: it removes line breaks and extra spaces so a query fits on one line, for logs, config files or code strings.
How it works
The tool parses your query with the open-source sql-formatter library, using the grammar of the
dialect you pick: MySQL, PostgreSQL or SQLite. The dialect matters for things like
quoting (`name` in MySQL, "name" in PostgreSQL), operators such as :: casts or ->>
JSON access, and dialect-specific keywords.
Everything runs in your browser; your query is never uploaded. When you share a link, the query is
stored in the part of the URL after #, which browsers do not send to the server.
Example
Before:
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.created_at>='2026-01-01' group by u.id,u.email having count(o.id)>5 order by orders desc limit 10;
After formatting:
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.created_at >= '2026-01-01'
GROUP BY
u.id,
u.email
HAVING
count(o.id) > 5
ORDER BY
orders DESC
LIMIT
10;
Limitations
- The formatter changes layout, not meaning. It does not check that tables or columns exist, and it does not optimise or run the query.
- Very unusual vendor syntax (stored procedure bodies, some DDL options) may be laid out less
neatly than plain
SELECT,INSERT,UPDATEandDELETEstatements. - If the query cannot be parsed, for example because of an unclosed quote, you get an error instead of output. Fix the syntax and try again.
Frequently asked questions
Does formatting change what my SQL query does?
No. Only whitespace, line breaks and keyword case change. The tables, conditions and values stay exactly the same, so the formatted query returns the same result.
Which SQL dialects are supported?
MySQL (and MariaDB-style syntax), PostgreSQL and SQLite. Pick the one your database uses so that quoting and dialect-specific operators are understood correctly.
What is the difference between Format and Minify?
Format spreads the query over several indented lines for reading. Minify puts it on a single line with minimal spacing, which is handy for logs, environment variables or strings in code.
Is it safe to paste production queries here?
The query never leaves your browser: formatting runs locally and nothing is uploaded or stored. As a habit, still avoid pasting real passwords or personal data into any web page.
Can I format several statements at once?
Yes. Separate the statements with semicolons and each one is formatted in turn.
Does it validate my SQL?
Only as far as parsing goes: badly broken syntax produces an error. It cannot know your schema, so a query that formats fine can still fail on the database because of a wrong column name.