DiagramDB / SQL Minifier

SQL Minifier

Collapse a query onto one line for an environment variable, a JSON payload or a log search. Comments go, whitespace shrinks, string literals stay exactly as written.

276 → 214 characters (22% smaller)
Minified

What gets removed, and what never does

The minifier walks the query character by character, the way a SQL lexer does. It removes -- line comments and /* */ block comments, collapses runs of spaces, tabs and newlines into one space, and drops spaces next to punctuation such as commas, parentheses and =. It never edits anything inside quotes, so 'paid -- not a comment' in the sample survives intact. That’s the difference from a naive find-and-replace, which would corrupt that string.

Need it readable again? Paste it into the SQL formatter.

Questions

Is minified SQL faster?

Not meaningfully. Databases parse whitespace in microseconds, and prepared statements are parsed once. Minify to fit SQL into a config value, a JSON string, a log line, a URL parameter or a spreadsheet cell, not for speed.

Does the minifier change string literals?

No. Text inside single quotes, double quotes, backticks, square brackets and PostgreSQL dollar quotes ($$ … $$) is copied exactly, including spaces and characters that look like comments.

Why keep some comments?

Optimizer hints such as /*+ INDEX(t idx) */ in Oracle and MySQL are written as comments but change the execution plan. Leave “Keep /*+ hints */” on to preserve them.

How do I reverse it?

Paste the minified query into the SQL formatter on the home page; it will be expanded back into readable, indented SQL. Stripped comments cannot be recovered, so keep the original.

Related tools