SQL Formatter
Paste a query, pick a dialect, then beautify or minify. Copy clean SQL for reviews, docs and debugging — nothing leaves your browser.
INPUT
OUTPUT
Why format SQL before sharing or reviewing it?
What this tool does
This SQL formatter beautifies messy queries into readable, indented layouts or minifies them into compact single-line strings. Choose a dialect preset — Standard SQL, MySQL, PostgreSQL, or SQLite — so keywords and syntax quirks align with your database engine. Monaco-powered editors on both sides give you syntax-aware input and copy-ready output.
Why you need it
SQL copied from production logs, ORM debug output, or one-line migration scripts is often unreadable. Nested subqueries without indentation hide logic errors; inconsistent keyword casing makes code review slower. A formatted query lets teammates spot missing JOIN conditions, ambiguous column references, and accidental cartesian products before they reach production.
Minify mode serves the opposite need: shrink a query for logging pipelines, URL parameters, or embedded strings where every byte counts. Because queries may contain table names, customer IDs, or proprietary business logic, keeping formatting local in the browser avoids exposing schema details to external services.
How to use it
- Paste SQL into the input editor, or click Load sample to see a formatted example.
- Select the dialect that matches your database from the toolbar dropdown.
- Click Beautify for indented, multi-line output or Minify for a compact version.
- Copy from the output editor and paste into your ticket, pull request, or documentation.
Practical examples
- Code review prep: Beautify a teammate’s one-line SELECT before posting review comments on specific JOIN clauses.
- Documentation: Format migration scripts for an internal wiki so readers can follow CTE chains step by step.
- Debugging ORM output: Paste the raw query Django or Hibernate logged, then indent it to see whether the ORM added an unexpected subquery.
- Log compression: Minify a repetitive INSERT batch before storing it in a compact audit trail.
How it works
The formatter uses the open-source sql-formatter library, which tokenizes SQL into keywords, identifiers, operators, and literals, then reassembles them with consistent indentation and line breaks. Dialect presets adjust keyword lists and parsing rules — for example, MySQL backtick quoting versus PostgreSQL double-quote identifiers. Beautify preserves all tokens and only changes whitespace; the database would execute the same plan. Minify removes non-essential spaces and line breaks, though inline comments may collapse depending on placement.
When the parser encounters syntax it cannot handle, the status bar reports the error and the input editor highlights the approximate problem line — similar to the JSON Formatter workflow. Parsing and formatting never leave your browser; no query text is uploaded to Kitnax servers.
Common mistakes
- Wrong dialect: PostgreSQL-specific syntax like
::typecasts may confuse the Standard SQL preset. Match the dropdown to your engine. - Assuming minify is reversible: Minified output loses comments and readable structure. Keep the beautified original as your source of truth.
- Formatting incomplete snippets: A lone
WHEREclause without its SELECT cannot parse. Include enough context for a valid statement. - Trusting formatted output in production without testing: Formatting should not change semantics, but always run formatted migrations in a staging environment first.
FAQ
Which SQL dialects are supported?
Standard SQL plus MySQL, PostgreSQL and SQLite presets that adjust keywords and formatting quirks.
Does formatting change query meaning?
Beautify only changes whitespace and line breaks. Minify collapses space; keep a backup if you rely on unusual comment placement.
What happens if SQL cannot be parsed?
Beautify shows an error in the status bar and highlights the problem line in the input editor — similar to the JSON Formatter.
Can I format stored procedures or CTEs?
Yes. Common SELECT, INSERT, UPDATE, DELETE, WITH, and JOIN patterns format well. Exotic vendor extensions may need manual touch-up.
Is my SQL uploaded?
No. Formatting runs entirely in your browser.