SQL Minifier
Compress SQL queries by removing whitespace and comments for optimal performance
Squash a query into one compact line
Sometimes SQL has to travel in a cramped space: a single-line config value, a command-line argument, a log message, an environment variable or a string literal in source code. The SQL Minifier removes comments and turns all runs of whitespace, including line breaks, into single spaces so a multi-line query becomes one compact line.
How to minify
- Paste your statement into the Source Query area, or press Sample to load a commented example. Clear empties the field.
- Click Minify SQL Query.
- Look at the Compressed Output. Three badges above it report the Original length, the Minified length and the percentage Saved.
- Press Copy to take the result.
What is removed
- Block comments written between slash-star and star-slash markers.
- Line comments that start with two hyphens, through to the end of the line.
- Extra spaces, tabs and newlines, which become a single space.
- Leading and trailing spaces around the whole statement.
Good moments to use it
Embedding a query in a JSON or YAML file where line breaks are awkward. Pasting a statement into a shell command without escaping newlines. Reducing noise in a log line when you record the SQL your service ran. Stripping developer notes from a query before you share it with a client. Checking how much of a query's length was whitespace and commentary.
Caveats before you paste it into production
The minifier uses plain pattern matching rather than a full SQL parser, which leads to a few edge cases. A double hyphen inside a string literal, such as a value like 'a -- b', will be treated as the start of a comment and the rest of that line removed. Runs of spaces inside quoted strings are also collapsed to one, which could alter a literal that depended on its spacing. Special comments that carry meaning, such as MySQL version hints or Oracle optimizer hints written in comment form, are removed along with ordinary ones. Spaces around commas and operators are kept, so the result is compact rather than as short as possible. Always compare the minified statement with the original against a test database. Minifying does not speed up execution, since databases ignore whitespace. Everything happens in your browser.
Related Tools
Related Tools