A blazing-fast, dependency-free SQL minify for the command line. Removes comments and collapses whitespace so your SQL is ready for logs, APIs, or inline embedding.
- β
Removes
--style comments (outside of quotes) - β Collapses all whitespace (tabs, newlines, spaces) into a single space
- β
Preserves quoted strings (
',",`) - β Outputs minified SQL as a single line
- β Native support on any machine with Bash + Perl (no external dependencies!)
Most SQL minification tools:
- β Require installing Node.js, Python packages, or NPM libraries
- β Aren't optimized for CLI usage or piping workflows
- β Ignore SQL quoting edge cases (e.g. comment symbols inside strings)
This tool is:
- π§ 100% shell-native (just Bash and Perl)
- πͺΆ Lightweight β under 10 lines of Perl
- π§ Intelligent β skips
--comments unless inside quotes - π Ideal for scripting, CI/CD logs, and API payloads
./minify-sql.sh path/to/query.sql > output.sqlcat path/to/query.sql | ./minify-sql.shOr:
echo "SELECT * FROM users -- fetch all" | ./minify-sql.shbashperl(standard on macOS, most Linux distributions, WSL, and Git Bash for Windows)
There are currently no open source CLI tools dedicated to SQL minification.
- JS-based tools exist in browser environments or for bundlers
- Database tools sometimes offer formatting, but rarely minification
- Regex hacks fail on real-world SQL with comments inside strings
This tool fills that gap for developers and ops engineers who just want clean, reliable SQL output.
This project was written 100% using AI, specifically ChatGPT by OpenAI. It was designed, debugged, and documented with zero human coding beyond execution and copy/paste.
If youβre impressed, thank ChatGPT!
MIT β free to use, copy, and share.