SQL Minifier
Compress SQL into a single line without breaking strings.
SQL Minifier – Compress SQL Queries
The SQL minifier turns a nicely formatted, commented query into a compact single line. That is useful when you need to embed SQL in code, a JSON or YAML config, a log message, or a command-line call where line breaks get in the way.
What it does
- Removes
--line comments,#comments (MySQL), and/* block */comments. - Collapses all whitespace — spaces, tabs, and line breaks — to the minimum needed.
- Removes spaces around punctuation such as commas, parentheses, and operators.
What it never touches
- String literals in single quotes, including escaped quotes (
'it''s') and backslash escapes. - Quoted identifiers in double quotes and MySQL backticks.
- PostgreSQL dollar-quoted strings (
$$ ... $$and$tag$ ... $tag$), commonly used for function bodies. - Optimizer hints – MySQL
/*! ... */version comments and Oracle/*+ ... */hints are kept by default because they change query behaviour.
The minifier is careful with operators: it never joins two characters into a comment marker, so a - -1 stays valid instead of turning into a--1.
Options
- Keep comments – keep comments, converted to
/* */style so they are safe on one line. - Keep hints – turn off to remove optimizer hints as well.
Size savings
The savings chips show how much smaller the query became. For long reports with many comments, savings of 40% or more are common. Keep the formatted, commented version in version control as the source of truth, and generate the minified one only where a single line is required.
Related tools
Make a minified query readable again with the SQL Beautifier, escape it for use in code with SQL Escape, or inspect INSERT data with the SQL Viewer.
Frequently Asked Questions
Can minifying change the result of my query?
No. Only comments and insignificant whitespace are removed. Strings, identifiers, and hints stay as they are, so the database executes the same statement.
Which databases are supported?
The minifier works on the token level and handles syntax from MySQL, MariaDB, PostgreSQL, SQL Server, Oracle, and SQLite, including their quoting styles.
Why are optimizer hints kept?
MySQL /*! */ comments and Oracle /*+ */ hints affect how the query runs. Turn off Keep hints if you want them removed.