SQL Formatter
Beautify and format messy SQL queries — across dialects, in your browser.
Beautify and format messy SQL across many dialects — instantly and privately in your browser. Free. No sign-up. Runs in your browser, nothing is uploaded.
Formatted
Your formatted SQL will appear here.Paste a query, pick your database's dialect, and the formatted version appears as you type: one clause per line, columns and conditions indented underneath, keywords in the case you choose. Indent with 2 spaces, 4 spaces or a tab, switch to Minify for a one-line version, then copy the result or download it as a .sql file. Fifteen dialects are supported, from Standard SQL and PostgreSQL to BigQuery, Snowflake, T-SQL and DuckDB.
Before and after
A typical one-liner from a log or an ORM:
select c.name, count(o.id) as orders, sum(o.total) as revenue from customers c left join orders o on o.customer_id = c.id where o.created_at >= '2026-01-01' and c.country in ('DE','AT') group by c.name having count(o.id) > 3 order by revenue desc limit 10;
Formatted with PostgreSQL, 2 spaces and UPPER keywords, this is the exact output:
SELECT
c.name,
count(o.id) AS orders,
sum(o.total) AS revenue
FROM
customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE
o.created_at >= '2026-01-01'
AND c.country IN ('DE', 'AT')
GROUP BY
c.name
HAVING
count(o.id) > 3
ORDER BY
revenue DESC
LIMIT
10;
Notice what the layout makes visible: the WHERE clause filters on o.created_at, a column from the right side of a LEFT JOIN. Customers without orders have NULL there and are filtered out, so this LEFT JOIN behaves like an INNER JOIN. In the one-liner that is easy to miss; laid out clause by clause, it stands out. If you meant to keep customers without orders, the date condition belongs in the ON clause.
Picking the right dialect
The dialect tells the formatter which syntax to expect. When the query uses something the chosen dialect does not know, you get a parse error instead of output:
| Syntax in your query | Belongs to | Fails in Standard SQL? |
|---|---|---|
id::text (type cast) | PostgreSQL, also Redshift, Snowflake and DuckDB | Yes |
[order id] (bracketed name) | SQL Server (T-SQL) | Yes |
`id` (backtick name) | MySQL, MariaDB, BigQuery, Spark | No, but pick the dialect anyway |
QUALIFY | BigQuery, Snowflake, DuckDB and others | No error, but it is glued onto the FROM line instead of getting its own clause |
{{ ref('orders') }} (dbt Jinja) | Templates, not SQL | Yes, in every dialect |
If you are not sure, start with Standard SQL. If it errors, the message names the line and column, which usually points straight at the dialect-specific bit.
Minify: when one line is what you want
Minify is for transport, not for reading: a query stored in an environment variable, embedded in a JSON config, or pasted into a one-line log search. It collapses all whitespace to single spaces and removes ordinary comments, but leaves anything inside quotes alone, including doubled quotes like 'it''s' and, in MySQL, BigQuery, Spark, ClickHouse and MariaDB, backslash escapes like 'it\'s'. Optimizer hints (/*+ INDEX(...) */) and MySQL's version comments (/*!50000 ... */) stay in, because removing them would change how the query runs.
Keep the formatted version as your source of truth and minify only at the edge where the query leaves your hands.
UPPER, lower or preserve?
SQL keywords are case-insensitive, so this is about readability. UPPER is the long-standing convention and separates keywords from your table and column names at a glance. lower is common in analytics code bases (many dbt projects use it) where queries read more like prose. Preserve leaves keywords exactly as typed, which is the polite choice when you are only re-indenting a colleague's query. What matters is picking one per project and sticking to it, so diffs in version control show logic changes rather than case changes.
What a formatter does not do
- It does not validate. A query can format perfectly and still reference a column that does not exist. Only your database can tell you that.
- It does not understand templates. Jinja tags in dbt models or placeholders from your application code are not SQL. Format the compiled query instead.
- It does not optimize. Layout makes problems like the LEFT JOIN above visible, but fixing them is up to you.
Formatting happens in your browser, so production-shaped queries with real table names never leave your machine. For the API payloads that sit next to your queries, the JSON formatter does the same job, and the Base64 encoder / decoder handles encoded values you find in query results.
Frequently asked questions
Related tools
All Developer tools →- JSON FormatterFormat, beautify and minify JSON with instant validation — all in your browser.
- Base64 Encoder / DecoderEncode text to Base64 or decode it back — instantly and privately in your browser.
- URL Encoder / DecoderEncode or decode URLs and query components instantly and privately in your browser.
