Skip to content
DevToolKit

SQL Minifier

Compress SQL queries by removing comments and collapsing whitespace while safely preserving string literals.

SQL Utility

SQL Minifier

Configuration

Remove CommentsStrip -- and /* */ comments
Collapse WhitespaceMultiple spaces → single space
Remove Trailing SemicolonFor log-ready single statements
Safe Minification

String literals, quoted identifiers, and PostgreSQL dollar-quoted strings are never modified — only whitespace and comments outside of strings are touched.

SQL Input
Minified Output
Was this tool helpful?

How to Use

Compress SQL queries by removing comments and collapsing whitespace while preserving the exact meaning of your query. String literals and quoted identifiers are never modified.

  1. Paste SQL: Enter your formatted SQL query into the input panel. Multi-statement scripts with semicolons work too.
  2. Configure options: Toggle comment removal, whitespace collapsing, and trailing semicolon removal independently.
  3. Review stats: The statistics panel shows original size, minified size, bytes saved, and reduction percentage in real time.
  4. Copy result: Click the copy button to grab the minified SQL for use in your application logs, API payloads, or code strings.

About This Tool

Safe Tokenizer-Based Minification

Unlike regex-based minifiers that can accidentally strip whitespace inside string literals, this tool uses a proper tokenizer. The SQL is split into discrete tokens — string literals (single quotes with escaped '' sequences), double-quoted identifiers, backtick identifiers (MySQL), PostgreSQL dollar-quoted strings ($$...$$), single-line comments (--), block comments (/* */), whitespace runs, and code tokens. Only whitespace and comment tokens are modified; string literals pass through untouched. This guarantees the minified output is semantically identical to the input.

SQL Comment Styles

SQL supports two comment styles defined in the ISO SQL standard. Single-line comments start with two dashes (--) and extend to the end of the line — commonly used for inline annotations. Block comments use /* ... */ delimiters and can span multiple lines — often used for section headers or temporarily disabling query blocks. Both styles are recognized and removable by this tool, while the content inside string literals that happens to look like comments is always preserved.

Use Cases for Minified SQL

Minified SQL is essential for application logging where multiline queries break structured log parsers like ELK Stack or Datadog. ORM query logging in frameworks like Django, Rails, and Hibernate often produces heavily formatted SQL that becomes unreadable in log aggregators. Minification also reduces payload size when SQL is transmitted over HTTP APIs (common in database-as-a-service platforms), fits queries into character-limited fields in monitoring dashboards, and makes SQL strings more manageable when embedded directly in application code.

Why Use This Tool

Instant, Private SQL Processing

SQL queries often contain sensitive information — table names reveal your schema, WHERE clauses expose business logic, and string literals may contain actual data values. This tool processes everything entirely in your browser using a JavaScript tokenizer. No SQL is ever transmitted to any server, making it safe for production queries, internal schemas, and queries containing customer data references.

The real-time statistics panel helps you quantify the space savings — typical formatted SQL with comments achieves 40-70% size reduction when minified.

FAQ

Does the SQL minifier change the meaning of my query?
No. The minifier only removes comments and collapses whitespace outside of string literals. All quoted strings, identifiers (backticks and double quotes), and PostgreSQL dollar-quoted strings are preserved exactly as written. The output is semantically identical to the input.
What SQL dialects are supported?
The tokenizer handles standard SQL string literals (single quotes with '' escaping), double-quoted identifiers, backtick identifiers (MySQL), and PostgreSQL dollar-quoted strings ($$...$$ and $tag$...$tag$). Comment styles -- and /* */ are recognized across all dialects.
Why would I minify SQL?
Common uses include: embedding queries in application log lines where multiline text breaks log parsers, reducing payload size for SQL sent over HTTP APIs, fitting queries into configuration fields with character limits, and cleaning up queries copied from formatted SQL editors before pasting into code.
Can I keep the comments and just remove extra whitespace?
Yes. Toggle off 'Remove Comments' in the configuration panel. The minifier will preserve all comments while still collapsing consecutive whitespace into single spaces. This is useful when comments contain important context like ticket numbers or author notes.