Why format SQL?
SQL written in application code tends to be ugly — one long line with no indentation, or broken awkwardly across strings. Pasting it into a database client or code review is painful. A formatter converts the raw query into a readable, multi-line form where each clause (SELECT, FROM, JOIN, WHERE, GROUP BY) starts on its own line, columns line up, and subqueries are properly indented. Pasting back into your ORM / repository, you usually want the minified form — one line, no excess whitespace, ready for the network.
Dialect differences that matter
- MySQL & MariaDB — backticks (
`column`) for identifiers,LIMITfor paging,AUTO_INCREMENTkeyword. - PostgreSQL — double-quotes (
"column") for case-sensitive identifiers,LIMIT ... OFFSET,RETURNINGclause,ILIKE. - T-SQL (SQL Server) — square brackets (
[column]) for identifiers,TOP Ninstead of LIMIT,OFFSET ... FETCH NEXTfor paging. - Oracle PL/SQL — no auto-increment (sequences instead),
ROWNUMorFETCH FIRST, dual table idioms. - BigQuery — standard SQL-ish with backticks for project.dataset.table,
STRUCTandARRAYtypes,UNNEST.
Picking the right dialect here ensures the formatter recognises keywords like TOP, ILIKE, or UNNEST correctly and doesn't mangle dialect-specific identifier quoting.
When to minify
Minify when you're committing a query into a string literal (ORM, stored procedure source, migration file), logging traffic, or sending it over a network where wire-size matters. Minification removes line breaks and collapses repeated whitespace while preserving everything inside string literals and comments. The parse tree and execution plan are byte-identical to the formatted version.
Privacy & offline
This formatter runs in your browser using the open-source sql-formatter library. Your queries are never uploaded, logged, or sent to a server. Once the page loads, the tool works offline.
Related tools
- JSON Formatter — for API responses and config files.
- Regex Tester — for text pattern matching.
- Cron Expression Descriptor — explain cron schedules in plain English.
