How to use it
- Paste your SQL
One query or a whole script; separate statements with semicolons.
- Pick the dialect
So vendor syntax like PostgreSQL ::casts or SQL Server [brackets] is understood.
- Set the style and copy
Keyword case and indentation, or minify for a one-line version.
Why format SQL at all
Queries copied from application logs, ORMs and query plans arrive on a single line. Formatting puts each clause (SELECT, FROM, JOIN, WHERE, GROUP BY) on its own line and indents sub-queries, so you can see the joins and conditions at a glance and spot the missing one. Consistent formatting also makes code review and version-control diffs of migrations and views much easier.
Choose the right dialect
The formatter needs to know which database you use, because each has its own syntax: PostgreSQL's :: casts and $$ function bodies, MySQL's backtick identifiers, SQL Server's [brackets] and TOP, Oracle's PL/SQL blocks, BigQuery's STRUCT and backtick table paths. With the wrong dialect, those parts may be split in odd places or rejected.
Upper-case keywords?
It is a style choice, not a rule: SQL keywords are case-insensitive. Upper case makes keywords stand out from table and column names, which is why many teams prefer it; others find lower case calmer to read. Pick one and use it everywhere. "Preserve" leaves your keywords as you typed them.
Minify
Minify removes comments and extra whitespace, but never touches text inside quotes or quoted identifiers. Use it to paste a query into a log search, a spreadsheet cell or a single-line config value. Pulling the query's results as JSON? Format them with the JSON formatter.
The formatting engine is the open-source sql-formatter library (MIT licence), bundled into this page.