SQL Formatter & Minifier
Format or minify SQL in your browser with a real parser — eight dialects, including Redshift, Spark, BigQuery and Trino.
Runs entirely in your browser — nothing is uploadedInput
Formatted
About the SQL Formatter & Minifier
Paste SQL, pick your engine, and get it back readable — or squeezed onto a single line. The dialect picker is not decoration. Format runs a real grammar for each of eight dialects (Standard SQL, PostgreSQL, MySQL/MariaDB, Amazon Redshift, Spark SQL, BigQuery, SQLite and Trino/Presto), so SELECT TOP 10, LATERAL VIEW EXPLODE, :: casts, LISTAGG … WITHIN GROUP and backtick-quoted names are understood rather than guessed at. Keyword case, data-type and function case, indent width, tabs versus spaces, whether AND lands at the start or the end of a wrapped line, the wrap width and the blank lines between statements are all adjustable, and everything re-renders as you type.
The non-obvious part of multi-dialect SQL is not keywords, it is string escaping — and it differs in ways that quietly change what your query means. Redshift, PostgreSQL, SQLite and Trino escape a quote by doubling it, so 'O''Brien' is one value, and they treat a backslash as an ordinary character. Spark SQL and BigQuery do the exact opposite: they have no '' escape at all and use \' instead, so to them 'O''Brien' is *two adjacent string literals*, not one name. Run that through a formatter that assumes standard escaping and it will happily reflow SQL it has misread. This tool lexes your input with the chosen dialect's own rules and warns you, with a line and column, when a literal will not be read the way you obviously intended — including the reverse case, where a \' written for MySQL ends a Redshift literal early and leaves the rest of the line dangling.
Minify is not a regex over whitespace, because that is precisely how minifiers corrupt SQL. Two hazards do most of the damage: pushing a - -b together produces a--b, which is a line comment that silently deletes the rest of that line; and joining 'a' 'b' produces 'a''b', one literal where there were two. Here a space is removed only when the two characters either side provably cannot fuse into a different token, and a space is never *inserted* where you did not have one. Comments are stripped by default, with a deliberate exception for the comments that are not really comments: /*+ BROADCAST(t) */ optimiser hints and MySQL's /*! … */ conditional blocks are executable, so dropping them would change your query plan or your results. If you keep ordinary comments, the newline after every -- is kept too, because it has to be.
Formatting uses a grammar, which means it refuses input it cannot parse rather than emitting something plausible and wrong. When that happens you get one line naming the token, the line and the column — not the ninety kilobytes of parser-generator trace the underlying library actually throws — and the separate checks for unterminated strings, unterminated block comments, unclosed quoted identifiers and unbalanced parentheses usually point at the real cause before the parser even gets a say. Minify never parses, so it still works on the things the formatter rejects: half-written queries, stored-procedure bodies, and Redshift $$ … $$ UDF blocks, which it treats as one opaque token. One more guard worth knowing about: the dense-operator option can render a - -b as a--b, so the output is scanned for comments that were not in your input and the spacing is restored if any turn up.
Everything runs inside your browser using standard web APIs. Your data is never uploaded, never stored on a server, and never leaves your device — you can confirm that by opening your browser devtools Network tab, or by switching off your Wi-Fi and using the tool offline.
Frequently asked questions
Does picking the wrong dialect just change which words get capitalised?
No — it changes how your SQL is read. String escaping is the clearest example: Redshift reads 'O''Brien' as one value, while Spark and BigQuery read it as two literals side by side, because neither supports '' as an escape. Backtick-quoted names are identifiers in MySQL, Spark and BigQuery and a syntax error in PostgreSQL and Trino. Double quotes wrap an identifier in PostgreSQL, Redshift, SQLite and Trino, but a string literal in MySQL, Spark and BigQuery. Pick your real engine and the tool applies that engine's rules, including when it warns you.
Why did it refuse to format my query instead of just tidying it up?
Because it parses rather than pattern-matches, and confidently-wrong SQL is a worse outcome than an honest no. The message gives the line and column of the token it choked on, and the unterminated-quote, unclosed-identifier and unbalanced-parenthesis checks usually name the real cause. If your syntax is valid but exotic, switch off Standard SQL first — that grammar rejects plenty of legal vendor syntax. Minify still works on anything the formatter rejects, since it never parses.
Is minified SQL safe to paste straight into a client?
For the whitespace, yes. A space is only deleted between two characters that cannot merge into a different token, so a - -b keeps its gap rather than collapsing into the line comment a--b, and two adjacent literals never fuse into one. The thing to check is comments: stripping is on by default. Optimiser hints (/*+ … */) and MySQL conditional blocks (/*! … */) are always kept because they are executable, but ordinary comments are dropped — turn off Strip comments if you need them.
Can it format a stored procedure or a Redshift UDF?
Not reliably. The formatter explicitly does not support stored-procedure bodies or changing the statement delimiter away from a semicolon, and it rejects Redshift's $$ … $$ UDF bodies outright. Minify handles both, because it treats a dollar-quoted block as a single opaque token and never looks inside it — so you can still collapse such a script safely, you just cannot pretty-print it.
How big a script can I paste?
There is no upload, so the ceiling is your own machine. Parsing costs roughly four microseconds per byte on the main thread — about half a second for 100 KB, five seconds for a megabyte — so above about 120 KB the tool stops re-formatting on every keystroke and gives you a Run button instead. Minify is a single lexical pass, roughly forty times faster, and keeps running live well past a megabyte.
Does this validate my SQL?
Partly, and it is specific about which part. It will tell you that a query does not parse and where, and it separately reports unterminated strings, unterminated block comments, unclosed quoted identifiers and unbalanced parentheses with a line and column. It knows nothing about your schema, so it cannot tell you a column or table does not exist, and a query that formats perfectly can still fail on the server.