SQL Minifier

Compress SQL to one line, safely stripping comments.

Input
SQL input
Output
Result

About this tool


Minifying collapses a query onto one line and removes comments. The usual reason is embedding: a single-line query drops cleanly into a JSON field, a config value, a log entry or a command-line argument without escaping newlines.

The part that requires care is comment removal. A naive implementation that deletes everything after -- will corrupt any string literal containing those characters, which is exactly the kind of bug that surfaces in production rather than in testing.

How to use it

  1. Paste or upload your sqlDrop a file onto the input pane, use the file picker, or paste the text directly.
  2. Adjust the options if neededThe defaults suit most input; open Options to change the behaviour.
  3. MinifyPress Minify, or use Ctrl+Enter (Cmd+Enter on macOS).
  4. Copy or downloadCopy the result, or download it as a .sql file.

Worked examples


Each example below is executed against this tool by the test suite, so what you see is what the tool actually produces.

Comments removed, literal preserved

Input

-- fetch active users
SELECT a, /* inline */ b
FROM t
WHERE s = 'value with -- dashes'

Output

SELECT a, b FROM t WHERE s = 'value with -- dashes'

Both comments are gone, but the dashes inside the string literal are untouched.

What to watch for


The details that decide whether a conversion is correct, and where information can be lost without any error being raised.

String literals are parsed, not pattern-matched
The query is walked character by character while tracking quote state, so a literal like 'rate -- special' keeps its dashes and a value containing /* survives intact. Doubled quotes inside a literal, the SQL escape convention, are handled correctly.
Both comment styles are removed
Line comments from -- to end of line and block comments between /* and */ are both stripped, and each is replaced with a single space so tokens on either side do not merge into one identifier.
Minifying loses documentation permanently
Comments frequently carry the reason a query is written a particular way, an index hint, a workaround, a business rule. Keep the formatted version as your source of truth and treat the minified form as generated output.
Performance is unaffected
Whitespace and comments are discarded by the SQL parser before planning, so a minified query executes identically. The benefit is purely in transport and embedding, not speed.

Limitations


  • Comments are removed permanently; keep the formatted version as the source.
  • Does not rename identifiers or otherwise rewrite the query.
  • Processing happens in your browser, so very large inputs are bounded by available memory. Files above roughly 10 MB are handled but will feel slower, and multi-hundred-megabyte files are better suited to a command-line tool.

Questions


Will minifying make my query run faster?
No. The parser discards whitespace and comments before planning, so execution is identical. The benefit is fitting the query into a single-line context.
Are my string literals safe?
Yes. Quote state is tracked while parsing, so -- and /* inside a literal are preserved as data.