SQL minifier
Processed in your browser · nothing is uploaded
Collapses a SQL statement onto one line and strips comments, without touching what is inside a string literal, which is where every naive whitespace-squasher goes wrong.
How to use the sql minifier
The whole difficulty is string literals. A regex that replaces runs of whitespace with a single space will happily rewrite WHERE note = 'a b' into 'a b', silently changing what the query matches. The minifier here tracks quoting, so text inside a literal survives exactly, doubled apostrophes included.
Comments are removed on the same terms: -- to end of line and /* … */, but only where they are not inside a string. A URL in a literal contains -- surprisingly often, and a comment stripper that does not know it is inside a quote will truncate the value.
Worth saying plainly: minifying SQL saves almost nothing. Query text is a rounding error next to the work the database does, and a minified query is far harder to debug in a slow-query log. The genuine uses are fitting a statement into a single-line config value, a migration tool that wants one statement per line, or a log line that must not wrap.
Questions
No. Quoting is tracked, so whitespace and comment markers inside a literal survive exactly.
No, essentially not at all. The parse is trivial next to the query. The real uses are config values and single-line logs.
Both -- to end of line and /* … */, except where they appear inside a string.
It treats the input as text, so multiple statements survive with their semicolons, but each will run onto the same line.
No. Everything runs in your browser, which matters when the file holds credentials or customer data.