WoluTools
← About this tool

developer · Browser tool

SQL Formatter

Paste a query, get it indented and consistently cased — or collapsed onto one line. Strings and comments are parsed first, so nothing inside them is touched.

Runs in your browserNothing is uploadedHow it works
Free toolNo account · no size limitFree, unlimitedRuns offline once the page has loaded.

Before

Options

After

What this does

The query is read character by character into tokens before any formatting happens: quoted strings, quoted identifiers, line comments, block comments, numbers, words and operators. Only then are the line breaks and the keyword casing applied, and only to tokens that are actually keywords. That ordering is the whole trick. A formatter that works by search and replace will happily turn WHERE note = 'order from the old queue' into something with a line break in the middle of the string, and the query stops meaning what it meant.

Where quoting differs between dialects

PostgreSQL uses double quotes for identifiers and doubles an apostrophe to escape it inside a string. MySQL adds backticks for identifiers, accepts a backslash as an escape character inside strings, and treats # as a line comment. SQL Server wraps identifiers in square brackets, where a literal closing bracket is written twice. SQLite is relaxed and accepts all three. Picking the right dialect above changes how the tokeniser reads those characters, which matters when an identifier or a string contains one of them.

Dollar quoting

PostgreSQL lets you open a string with $$ or $tag$ and close it with the same marker, which is how function bodies avoid escaping every apostrophe. Anything between the markers is literal text, including apostrophes and semicolons, so the formatter treats the whole run as one token and leaves it exactly as written.

What minify removes

Minify strips comments and collapses runs of whitespace. Comments have to go: a line comment runs to the end of the line, so folding the query onto a single line would comment out everything after it. Block comments are removed too, for consistency. If the comments matter to you, keep the expanded output.

Honest limits

This is a formatter, not a parser with a grammar. It follows clause keywords, commas, parentheses and CASE blocks, which covers ordinary queries including CTEs, joins and nested subqueries. Vendor-specific procedural blocks — PL/pgSQL bodies, T-SQL control flow, stored procedure definitions — are laid out by the same general rules and may not match the house style of your database. The query is never executed and never validated; formatting a query does not tell you it will run.