How to use
- Paste or type your query into the SQL input box. As long as it stays under 50,000 characters, the formatted version updates while you type.
- Set Dialect to the database you actually run — PostgreSQL, MySQL, SQL Server and a dozen others — so the parser accepts that vendor’s syntax.
- Choose a Keyword case: UPPERCASE, lowercase, or Preserve to leave
Selectandselectexactly as you wrote them. - Pick an Indent unit — two spaces, four spaces, or tabs — to match your project’s house style.
- Read the result in Formatted SQL, then Copy it or Download it as a
.sqlfile. For a query over the live limit, press Format (or Ctrl+Enter) to run it on demand.
How it works
Behind the box is the open-source sql-formatter library, running in the page. It doesn’t nudge your whitespace around; it tokenises the query against the grammar for the dialect you picked, builds a structured list of clauses, keywords, identifiers and literals, then re-prints that structure with consistent spacing and line breaks. Only two things in the output are yours to steer — the case of reserved keywords and the indent unit. Identifiers, string literals and numbers pass through untouched, which is why switching to UPPERCASE never rewrites a table name or a value inside quotes.
Take this one-liner, pasted with lowercase keywords into the Standard SQL dialect:
select id,email,created_at from subscribers where status='active' and created_at>='2026-01-01' order by created_at desc limit 50;
With keyword case set to UPPERCASE and a two-space indent, it comes back as:
SELECT
id,
email,
created_at
FROM
subscribers
WHERE
status = 'active'
AND created_at >= '2026-01-01'
ORDER BY
created_at DESC
LIMIT
50;
Each clause keyword lands on its own line, list items are indented one level, operators like >= get breathing room, and 'active' and 2026-01-01 are reproduced exactly. Paste several statements divided by semicolons and each is printed on its own, with a blank line between them.
Use cases & limitations
Turn to this when you’re staring at a wall of SQL someone else wrote: a query pulled from an ORM’s debug log, a one-line statement copied out of a stack trace, or a pull request where the indentation went to war with the diff. Laying the clauses out consistently makes the structure jump out, so a missing join condition or a mis-scoped OR is far easier to spot. It’s also useful for un-minifying generated SQL before you drop two versions into the text diff tool to see what genuinely changed.
The honest catch here: this is a parser, not a linter. It rewrites layout; it does not check your query against a real schema, and it won’t rescue broken syntax — if the chosen dialect can’t make sense of the tokens, you get a parse error pointing at a line and column rather than a best-effort guess. Parsing also runs on the page’s main thread, so very large scripts stop formatting live and wait for a manual Format. And the work is purely cosmetic: it will happily pretty-print an inefficient query without a word about performance. If what you have is actually JSON returned by a query rather than SQL itself, the JSON formatter is the tool you want; for pulling fields out of raw log lines, try the regex tester.