SQL formatter / minifier
Reformat SQL for readability (newline before major clauses, indented parens) or minify it to one line. Token-based, not a real SQL parser; dialect-specific syntax or deeply nested queries might format oddly. Runs on your device.
Runs on your device. The file is never uploaded.
SQL formatter / minifier reformats a SQL statement clause by clause, or squeezes it onto one line when mode is minify. Twenty clause keywords are recognised and printed uppercase; every other identifier keeps the case you typed. Both modes throw your comments away, and no grammar sits behind the pass to guarantee the result still runs.
Questions
What does format mode do to my query?
It puts a newline before each major clause, indents the inside of parentheses by two spaces, and breaks lists after each comma. The clause keywords it knows are SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, LIMIT, the JOIN family, UNION and UNION ALL, INSERT INTO, VALUES, UPDATE, SET, DELETE FROM and ON.
Does it uppercase my keywords?
Only the clause keywords it recognizes, which are printed in their canonical uppercase form. Everything else keeps the case you typed, including AND, OR, function names, table names and column names. So "select id from users" comes back with SELECT and FROM uppercased and the identifiers left alone.
What happens to my comments?
They are removed, in both modes. The tokenizer recognizes double-dash line comments and block comments and filters them out before anything is formatted. If the comments matter, keep your original, because this tool cannot give them back. String literals are the opposite case: they are kept whole, including doubled quotes inside them.
Is the formatted SQL guaranteed to still run?
No such guarantee is made. This is a token pass with no grammar and no dialect awareness, aimed at readability. Deeply nested subqueries and dialect-specific syntax can come out oddly spaced, and because comments are dropped the text is not identical to what you gave it. Read the output before committing it.
What does minify mode do?
Puts the whole statement on one line: comments removed, whitespace collapsed to single spaces, no space before a comma and one after it, and no padding inside parentheses. That is the form you want for pasting a query into a log line, a JSON field or a single-line config value.
Which SQL dialects does it know?
None specifically. There is one keyword list and no dialect setting, so Postgres, MySQL, SQLite and SQL Server all go through the same pass. Syntax unique to one of them is treated as ordinary tokens and passed through, which is usually fine and occasionally looks strange.