SQL Formatter
Clause-per-line SQL beautifier with keyword-case control; string contents are sacred.
The SQL you fish out of logs is one enormous line; the SQL in code review is hand-indented differently by every author. This tool applies stable layout rules: SELECT/FROM/WHERE clauses each take a line, top-level list items break at commas, parentheses indent as blocks, AND/OR stand on their own lines, and JOIN families plus subqueries land where readers expect them.
Layout runs after lexing: strings, comments and quoted identifiers are recognized as atomic tokens and preserved verbatim — the comma inside 'a,b' is not a list separator, and -- comments are not shredded. Keyword case is configurable (upper, lower, preserved), and a minify mode emits a single-line version for logs and diffs.
Why layout does not require understanding SQL
SQL has no unified grammar — window functions, CTEs and dialect keywords make a full parser expensive. But "readable" depends only on the lexical layer: which words are clause keywords, where quotes close, how parentheses nest. That is why this formatter handles every dialect by default — unrecognized words are just identifiers.
Strings and comments are inviolable
The spaces and commas inside WHERE city = 'New York' are data; reflowing them changes the query. The lexer treats a string as one indivisible token ('' escapes and backslashes included), and -- and /* */ comments are kept whole — only minify skips comments.
Frequently asked questions
- Which SQL dialects are supported?
- The lexical rules are dialect-neutral: routine statements from MySQL, PostgreSQL, SQLite and SQL Server all format correctly; backtick (MySQL) and double-quoted (standard) identifiers are both recognized. Complex control flow inside stored procedures may lay out imperfectly but never loses semantics.
- Can formatting change query results?
- No. Only whitespace and keyword case change, and neither carries meaning in SQL. Contents of strings and comments are untouched.
- What is minify for?
- Collapsing multi-line SQL into one line for logs, spreadsheets or diffs. Whitespace inside strings is unaffected.