SQL Beautifier

~/tools/sql $ ./format
query.sql
result.sql

SQL Formatter

Readable SQL reduces review time and prevents accidental logic changes. This formatter normalizes indentation, line breaks, and clause order for SELECT, INSERT, and DDL so complex joins and nested queries are easier to scan in docs and tickets.

How to use

  1. Paste a messy query from logs, ORM output, or migration scripts.
  2. Format with your preferred keyword casing style (uppercase is common) and check join conditions stay identical.
  3. Copy the formatted SQL into notebooks, README examples, or migration files after a quick execute-in-staging sanity check.

FAQ

Will formatting change query results?
Whitespace and casing do not alter semantics for standard SQL, but comments relocation might. Always test after aggressive refactors or dialect-specific hints.
Why did my vendor-specific syntax break?
PostgreSQL, MySQL, SQL Server, and others differ on JSON functions, identifiers, and escapes. Keep a dialect-appropriate test when using generic formatters.
Is minified SQL faster?
Parsers compile plans similarly; minification mainly saves network bytes. Maintain readability in source control and minify only if a pipeline requires it.