What is SQL, and why does the dialect matter?
SQL is the query language of relational databases, standardised in outline but implemented with dialect differences — quoting rules, functions, LIMIT versus TOP, date literals — by PostgreSQL, MySQL, SQLite, SQL Server and Oracle. A formatter normalises keywords, indentation and line breaks so a long query can be read and reviewed; a validator parses the statement to find syntax errors before it reaches the database.
Security note: Generated INSERT or IN-clause statements are for fixtures and migrations. In application code, values must go through parameterised queries — building SQL from user input by string concatenation is how SQL injection happens.
How to use SQL Minifier
- Paste the SQL to compress.
- Pick the dialect and decide whether comments should be kept.
- Copy the single-line result.
SQL Minifier features
- Collapses any SQL to a single line
- Removes -- and /* */ comments, or converts them to inline block comments
- Keeps string literals, quoted identifiers and parameters intact
- Dialect-aware tokenisation (MySQL # comments, SQL Server [brackets], PostgreSQL $$ quotes)
- Shows bytes saved and percentage
SQL Minifier example
Minify a commented query
Input:
-- active users
SELECT id,
name /* display */
FROM users
WHERE active = 1;Output:
SELECT id, name FROM users WHERE active=1;Frequently asked questions about SQL Minifier
Are string literals and comments handled safely?
Yes. The minifier tokenises the SQL, so whitespace inside quoted strings is kept and comments are removed (or converted to /* */ blocks if you choose to keep them).
Why keep comments?
Some teams use comments as query tags for monitoring tools (for example /* app:checkout */). Tick "Keep comments" to preserve them in block form on the single line.
Is the minified SQL still valid?
Yes. A single space is kept wherever two tokens would otherwise merge, so keywords, identifiers and operators stay separate.
What is this useful for?
Embedding SQL in JSON configs, log lines, URL parameters, code strings and anywhere a single line is easier to handle.
References
- PostgreSQL Documentation: SQL SyntaxLexical structure of SQL in PostgreSQL: identifiers, quoting, string constants and escaping.
- SQL As Understood By SQLiteThe SQL grammar accepted by SQLite, statement by statement, with railroad diagrams.
- SQL InjectionHow SQL injection works and why parameterised queries, not string building, are the defence.