How to use the SQL Formatter
- Paste one or more SQL statements into Input SQL (or open a
.sqlfile). - Select your dialect — this matters for things like backtick identifiers in MySQL,
::casts in PostgreSQL orTOPin SQL Server. - Choose keyword case and indentation. The formatted query updates as you type.
- Copy the result or download it as
query.sql.
What does a SQL formatter do?
SQL is whitespace-insensitive, so queries generated by ORMs, logged by a database or written in a hurry often end up on one enormous line. A SQL formatter parses the statement and re-prints it with each major clause — SELECT, FROM, JOIN, WHERE, GROUP BY, ORDER BY — starting a new line, column lists indented underneath and sub-queries nested one level deeper. That makes it far easier to spot a missing join condition, a misplaced OR or a column you forgot to group by.
Example
select u.id, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = 1 group by u.id
becomes
SELECT
u.id,
count(o.id) AS orders
FROM
users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE
u.active = 1
GROUP BY
u.id
Why the dialect setting matters
Every database extends SQL differently. Choosing the right dialect lets the formatter recognise vendor keywords and syntax instead of treating them as errors:
| Dialect | Examples it understands |
|---|---|
| MySQL / MariaDB | `backtick` identifiers, LIMIT 10, 20, ON DUPLICATE KEY UPDATE |
| PostgreSQL | :: casts, $1 parameters, RETURNING, dollar-quoted function bodies |
| SQL Server (T-SQL) | [bracketed] names, TOP (10), @variables, GO batches |
| BigQuery | STRUCT/ARRAY types, backtick project.dataset.table paths, QUALIFY |
| Oracle PL/SQL | :bind variables, CONNECT BY, q'[…]' strings |
If a query fails with a parse error, the most common cause is a dialect mismatch — try the database you actually run. The formatter is built on the open-source sql-formatter library and runs entirely in your browser, so production queries containing customer data never leave your machine.
Keyword case: upper or lower?
UPPERCASE keywords are the traditional convention and make the query structure stand out from table and column names; many modern teams prefer lowercase because it is easier to type and read. Pick one and stay consistent — linters such as SQLFluff can enforce it in CI. The Functions option controls built-ins like count() or coalesce() separately.
Comparing two versions of a query? Paste them into the Diff Checker. Exported results as JSON? Turn them into a spreadsheet with JSON to CSV.
Tools that pair well with the SQL Formatter
- CSV to JSON — Paste CSV or TSV and get a JSON array of objects.
- JavaScript Formatter — Unminify and pretty-print JavaScript, JSON or JSX with your preferred indentation and brace style — or strip whitespace and comments with a verified minifier.
- HTML Formatter — Paste minified or messy markup and get clean, consistently indented HTML — including embedded <style> and <script> blocks.
- CSS Formatter — Turn a minified stylesheet into readable CSS with one property per line and properly nested @media blocks.
Frequently asked questions
Does the formatter change what my query does?
Why do I get a parse error?
{{ var }} can also confuse it.Can I format several statements at once?
Is it safe to paste production queries?
WHERE clauses stay private.Are stored procedures and DDL supported?
CREATE TABLE, ALTER, INSERT, CTEs (WITH) and window functions are fully supported. Procedural blocks (PL/pgSQL, T-SQL control flow) are formatted on a best-effort basis.