SQL Formatter
Pretty-print SQL queries with keyword casing, indent and line-break rules for MySQL, PostgreSQL and SQLite.
What is SQL Formatter?
A SQL beautifier for reading and reviewing queries. It puts SELECT, FROM, WHERE and friends on their own lines, indents the columns and conditions under each clause, and can force a consistent keyword case.
How it works
The query is tokenized into words, strings, comments and placeholders, then re-laid-out by clause. Comma-separated lists inside parentheses stay inline until the line gets long enough to justify breaking, which keeps a short INSERT readable and a twenty-column SELECT reviewable.
- Paste the source. Drop in code, a stylesheet, a query or a selector list. Everything is read locally — the page never uploads what you paste.
- Choose the options. Indent width, quote style, keyword case or target browsers. The result updates as you change them, so you can see the effect immediately.
- Copy or download. Copy the result to the clipboard or download it as a file. Reset clears the form and returns every option to its default.
Examples
A one-line dashboard query
A 400-character SELECT with three joins becomes a clause-per-line statement where the join conditions line up and the filter is impossible to miss.
A parameterised query from application code
Placeholders survive untouched: `?`, `$1` and `:named` parameters come back exactly as they went in, so the query still binds correctly.
Common mistakes
Expecting a formatter to fix invalid code
Formatting is whitespace and quoting. A missing brace, an unclosed tag or an unquoted variable survives the round trip and is reported instead — check the findings list.
Minifying without running the tests afterwards
Even a safe, non-mangling minifier can expose an existing automatic-semicolon-insertion bug. The JavaScript Minifier keeps the newlines that matter, but re-run your tests before shipping.
Treating a rewritten query as verified
The SQL Dialect Converter translates the syntax it can prove; data types, casts and function differences are listed for review, not guessed. Run the converted query against a real database.
Renaming or reformatting generated files
Regenerating a formatter's output is a no-op only if the formatter is the same one that produced it. Keep generated code out of the round trip and format the source it came from.
Frequently asked questions
Which dialects are understood?
The clause keywords, quoting and placeholder styles shared by MySQL, MariaDB, PostgreSQL and SQLite. Dialect-specific constructs such as PostgreSQL's `::type` casts or MySQL's JSON functions are treated as ordinary tokens and copied through unchanged.
Why did my comment end up on its own line?
Comments are lints of intent, so the formatter gives them a line of their own at the current indent instead of burying them at the end of a clause. The text itself is never altered.
Can I keep my keywords lower-case?
Yes — pick `lowercase`, or `leave as written` to preserve whatever case the query already used while still fixing the layout.