SQL Formatter & Minifier
Paste a messy SQL query and format it for review, or minify it to a single line for logs, env vars, and string literals.
About SQL Formatter & Minifier
Paste a messy SQL query and format it for review, or minify it to a single line for logs, env vars, and string literals. This free SQL query formatter online and SQL minifier online runs entirely in your browser, so production queries that name real tables - and often sit next to customer data - are never uploaded. The tokenizer is string-safe: comments inside quotes, PostgreSQL dollar-quotes, backticks, and optimizer hints (/*+ and /*! */) stay intact. A live clause map lists CTEs, joins, and filters so a one-line dump from a log becomes readable before you copy it into a PR. Same shape as the JSON minifier: one URL, format and minify modes, Standard / PostgreSQL / MySQL / SQLite dialects.
How to Use SQL Formatter & Minifier
- Choose Format SQL (SQL query formatter) or Minify SQL (SQL minifier). Formatting is the default.
- Paste a query, drop a local .sql file (max 2 MB, read in the browser only), or load a JOIN / CTE / INSERT / PostgreSQL sample.
- Pick the dialect (or accept the detected one), set keyword case and indent for format, or keep optimizer hints when minifying.
- Read the clause map (CTEs, FROM, joins, WHERE / GROUP / ORDER / LIMIT), then copy or download the result. Nothing is uploaded.
SQL Formatter & Minifier Examples
Format a one-line log query
A SELECT with joins squashed onto one line expands so each SELECT item, JOIN, ON, WHERE, and ORDER BY sits on its own line with UPPERCASE keywords.
SQL minifier online for embeds
A formatted query becomes one line with comments stripped. Optimizer hints (/*+ INDEX */) and MySQL versioned comments (/*!40101 */) stay unless you turn them off.
CTE and JOIN outline
WITH active AS (...) SELECT ... JOIN orders is formatted with the CTE body indented. The clause map lists the CTE name, join type, and GROUP BY so you can review structure without reading every line.
PostgreSQL dollar-quotes
SELECT $body$ line -- still a string $body$::text stays one literal. A regex minifier would cut at --. Switch to the PostgreSQL dialect (or accept the sniff) for :: casts and $1 placeholders.
Strings that look like comments
VALUES (1, 'Ada -- not a comment') keeps the apostrophe-escaped string. Comment markers inside quotes are never treated as SQL comments.
Frequently Asked Questions about SQL Formatter & Minifier
- How do I use this SQL query formatter online?
- Paste your SQL (or drop a .sql file), leave Format SQL selected, pick Standard / PostgreSQL / MySQL / SQLite, and copy the indented result. Keyword case and indent (2 or 4 spaces) match your codebase. Everything runs in the browser.
- Is this also a SQL minifier online?
- Yes. The same page minifies SQL: comments and extra whitespace collapse to one line while string literals, dollar-quotes, and quoted identifiers stay untouched. Use minify for env vars, URL parameters, log lines, and SQL embedded in application strings.
- Is my SQL uploaded to a server?
- No. Tokenizing, formatting, and minifying run only in your browser. Production queries name real tables and often sit next to customer data, which is why a SERP widget or an ad-supported server-side formatter is a poor fit.
- Which SQL dialects are supported?
- Standard SQL, PostgreSQL, MySQL, and SQLite. Dialect changes quoting and comments: PostgreSQL dollar-quotes and :: casts, MySQL backticks / # comments / /*! versioned comments */, SQLite AUTOINCREMENT and [identifiers]. If the sniffer disagrees with your pick, use the detected dialect.
- Does minify break strings that contain -- or /* */?
- No. The tokenizer closes strings, dollar-quotes, and quoted identifiers before it looks for comments. 'Ada -- not a comment' and $tag$ -- still a string $tag$ survive minify. Naive regex minifiers fail this case.
- Are optimizer hints stripped when I minify SQL?
- Not by default. /*+ INDEX(...) */ and MySQL /*!40101 ... */ stay in the minified output because they change the plan. Ordinary -- and /* */ comments are removed. Uncheck Keep optimizer hints if you want those gone too.
- What is the clause map?
- A structure readout of CTEs, SELECT count, FROM tables, JOIN types, and whether WHERE / GROUP BY / ORDER BY / LIMIT appear. It is for reviewing a dumped query, not a query planner - the SQL is never executed.
- Does formatting change query meaning?
- No. Only whitespace, line breaks, keyword casing, and (on minify) comments change. Table names, column names, literals, and hints stay as written. The database returns the same result.
- How is this different from sqlformat.io or aiven's formatter?
- Those pages wrap a generic formatter and stop at pretty print. This URL is also a SQL minifier, keeps optimizer hints, is dollar-quote safe, sniffs the dialect, and shows a clause map - all client-side next to the JSON, JavaScript, and other minifiers on this site.
Related Tools
JSON Minifier & Formatter
Free online JSON minifier and formatter. Minify JSON to shrink payloads or beautify (pretty-print) JSON with 2-space indentation. Validates as you go - no upload required.
JavaScript Minifier
Free online JavaScript minifier. Compress and minify JS by removing comments and collapsing whitespace - smaller files, faster page loads. Runs in your browser, no upload required.
Diff Checker
Compare two texts side by side in your browser. Nothing is uploaded - safe for configs, logs, and contracts. Ignore whitespace or case, see word-level highlights, and copy a unified diff.