What this formatter does
It tokenizes your SQL and rebuilds it with consistent rules: clause keywords (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, JOIN, ON, SET, VALUES…) start new indented lines; commas and operators get spacing; strings and comments are preserved untouched; parentheses increase indentation.
What it doesn't do
- It's not a linter — syntax errors are left for your database to judge.
- It doesn't know your dialect's exotic syntax (PL/pgSQL bodies may need manual tidy-up).
- It never sends your query anywhere — everything runs in your browser tab.
Formatting conventions
Clause-first style: each main clause on its own line at the same level, sub-queries indented one level, AND/OR aligned under their WHERE. This matches the style used in most open-source projects and is easy to read in diffs.
Example — input: select u.id,u.name from users u where u.active=true order by u.id becomes:
SELECT u.id,
u.name
FROM users u
WHERE u.active = true
ORDER BY u.id;
How the conversion runs
format() is a keyword-and-state machine rather than a parser: it breaks the line before major clauses (SELECT, FROM, WHERE, JOIN, GROUP BY, ORDER BY), indents by nesting level, and flush() emits the result. Quote and comment state is tracked so a keyword inside a string literal is left alone. Because it never builds a syntax tree, it cannot change what the statement means — it only moves whitespace around.
Edge cases and hard limits
It does not validate SQL: a broken statement gets formatted just as cheerfully as a correct one. Dialect-specific quoting — backticks, double quotes, square brackets — is handled generically, so MySQL and PostgreSQL oddities may need a manual touch. Deeply nested subqueries produce very long indented lines, and extremely long statements format slowly because the whole text is processed at once.
Privacy: processed in your browser
The statement is reformatted as text in this tab. It is not sent to any database, not executed, and no connection string leaves the page.
Frequently asked questions
Will formatting change what the query does?
No. Only whitespace and line breaks change; keywords, identifiers and literals are untouched.
Does it support different dialects?
It uses generic rules. Dialect-specific syntax will not be broken, but the layout is not tuned per database.
Can I run the formatted query directly?
Yes, the semantics are unchanged — though running it against production without a test is a separate decision.