Skip to content
All tools
English

SQL formatter

Turn a one-line query from a log or an ORM into something you can read and review. Your SQL stays on this page.

Your data never leaves your device

Paste one query or a whole script.

Options
Output

How to use it

  1. Paste your SQL

    One query or a whole script; separate statements with semicolons.

  2. Pick the dialect

    So vendor syntax like PostgreSQL ::casts or SQL Server [brackets] is understood.

  3. 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.

Frequently asked questions

Does it check whether my query is correct?
It checks the syntax enough to format it and reports what it cannot parse, but it does not know your tables. A query can format nicely and still fail on the database.
Is my SQL sent to a server?
No. The formatter library is part of this page and runs in your browser; the page cannot make network requests.
Why did it reject my query?
Usually the dialect: switch to your database. Template placeholders such as {{name}} or :name may also confuse it; replace them with a value before formatting.