SQL Minifier
Minify SQL by stripping comments and extra whitespace.
What is SQL Minifier?
A SQL minifier is a tool that strips comments, collapses whitespace, and flattens multi-line SQL into a single line so the query takes up less space in source code, log messages, or embedded application strings. The minified output is semantically identical to the source, since SQL parsers ignore the trimmed characters.
Backend developers, DBAs, and data engineers use a SQL minifier when embedding queries inside JSON payloads, environment variables, or shell scripts. A 40-line annotated query collapses into a single line under 800 characters that fits in a Slack message.
Why use the SQL Minifier
- Embed queries in code without escape gymnastics. A single-line query fits in a string literal without backslash continuations.
- Shrink query log payloads. Application loggers and APM tools charge by ingest volume. Minified queries cut SQL log size in half.
- Faster copy-paste into clients. Pasting a flattened query into
psql,mysql, or a JDBC console runs immediately.
How to use the SQL Minifier
- Paste your SQL query or script into the input panel on the left.
- Click the Minify button at the top of the panel.
- Read the flattened SQL in the right panel. Parser warnings appear in red above the panels.
- Copy the result with the Copy button and paste it into your application code, log inspection field, or CLI client.
What gets removed
The SQL minifier performs lossless transformations only. No keyword is renamed, no clause reordered, and the execution plan is unchanged.
| Pass | Action |
|---|---|
| Whitespace collapse | Reduces runs of spaces, tabs, and newlines to one space |
| Line comment removal | Strips -- comment through end of line |
| Block comment removal | Removes /* ... */ including nested blocks |
| Trailing whitespace trim | Drops spaces before ; and at end of line |
| Empty statement collapse | Removes stray semicolons |
Whitespace inside string literals and quoted identifiers is preserved verbatim.
Size savings example
Input (256 bytes):
-- Active customers from last 30 days
SELECT
c.id,
c.email,
COUNT(o.id) AS order_count
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE c.created_at > NOW() - INTERVAL '30 days'
GROUP BY c.id, c.email
ORDER BY order_count DESC;Minified output (172 bytes):
SELECT c.id, c.email, COUNT(o.id) AS order_count FROM customers c LEFT JOIN orders o ON o.customer_id = c.id WHERE c.created_at > NOW() - INTERVAL '30 days' GROUP BY c.id, c.email ORDER BY order_count DESC;Typical savings:
| Input | Raw | Minified | Reduction |
|---|---|---|---|
| Simple SELECT | 180 B | 110 B | 39% |
| Reporting query with CTEs | 1.4 KB | 820 B | 41% |
| Stored procedure | 6.2 KB | 3.1 KB | 50% |
| Migration script | 12 KB | 6.4 KB | 47% |
Common use cases
- Embedding SQL in application code. Languages without raw multi-line strings handle minified queries more cleanly.
- Centralized logging. Datadog, Sentry, and CloudWatch ingest charges scale with payload size.
- Bash and CI scripts. Inline
psql -c "..."invocations work better with single-line queries. - Documentation and tickets. A one-line query in a Jira ticket avoids markdown formatting quirks.
Frequently asked questions
Is minified SQL reversible?
Whitespace removal is reversible by running the result through a SQL formatter, but the original comments are gone once stripped. Keep source files with comments in version control.
Does minifying break my SQL?
No, as long as the source query is valid. The minifier respects string literals, quoted identifiers, and comments inside strings. The execution plan is identical to the source query.
Does the database run minified SQL faster?
No. Database engines parse and plan a query the same way regardless of whitespace. The win is at the application and logging layer.
What dialects does the SQL minifier support?
The minifier works on PostgreSQL, MySQL, MariaDB, SQLite, MS SQL Server, and Oracle. It treats -- and /* */ as comments and recognizes standard delimiters across dialects.
Will the minifier strip my dollar-quoted strings or PL/pgSQL blocks?
No. Dollar-quoted bodies ($$ ... $$) and BEGIN ... END blocks are preserved verbatim. The minifier only collapses whitespace outside string and code-block boundaries.
Can I minify a query with parameter placeholders?
Yes. Placeholders like $1, ?, :name, and @param pass through unchanged.
Related tools
- JavaScript Minifier - shrink JavaScript bundles by stripping whitespace and shortening identifiers.
- CSS Minifier - strip whitespace and comments from CSS to shrink stylesheet bundles.
- HTML Minifier - collapse whitespace and remove comments from HTML markup.
- SQL Formatter - re-indent minified SQL into readable, dialect-aware formatting.
Related tools
ShotMark captures what you do here, in one click.
The traces, payloads, and tests you run by hand? ShotMark grabs the whole bug and hands it to your AI agent.