Format and beautify SQL queries — uppercase keywords, indent subqueries, break lines before major clauses. Handles SELECT, INSERT, UPDATE and CREATE TABLE.
Copy a query out of a log file and it lands as a single line of lowercase keywords with no indentation. This formatter reads that string and returns SQL a human can follow: major clauses each start on a new line, keywords are uppercased, subqueries indent one level, and compound phrases like GROUP BY stay together instead of splitting across lines.
The tokenizer handles single-quoted strings (with the '' escape), double-quoted and backtick identifiers, line comments (--), block comments, /* */), and qualified names like s.name. Everything runs in the browser; no query is uploaded to a server.
The page loads with a deliberately ugly query on one line: select s.name, count(*) as failures, avg(r.duration_ms) as avg_ms from requests r join services s on s.id = r.service_id where r.status >= 500 and r.created_at >= now() - interval '1 hour' group by s.name having count(*) > 10 order by failures desc limit 20; The formatter breaks it into 9 lines: SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT each start a new line, and every keyword is uppercased. Press Load Sample to cycle through an UPDATE with a subquery, a CREATE TABLE with column definitions, and a multi-row INSERT.
UPPER because that is the convention in every major SQL style guide.COUNT(*) stay inline.SELECT lists that are hard to scan horizontally.String literals are preserved exactly, including the doubled single quote that SQL uses to escape a literal apostrophe. A string like 'it''s here' survives a round-trip unchanged. Line comments and block comments are kept in the output and indented to the current depth, so a 3-line /* ... */ block above a WHERE clause stays where you put it.
Qualified names with dots (r.service_id, public.users) are treated as a single token so they do not get split across lines. Identifiers wrapped in double quotes or backticks ("order", user) are kept verbatim, including the quoting characters.
The formatter tokenizes text, not semantics. It does not validate syntax, resolve table names, check types, or detect missing FROM clauses. A query with a syntax error is still formatted, and the error is still there afterward. Use it to make a query readable before debugging it in a database client, not as a linting step that catches mistakes.
43 words
Formatting Options