Skip to content
PocketDesk
Your files are processed on your device, never uploaded

SQL formatter

  • On device
Input
Ln 1, Col 11 line0 BUTF-8

Paste, drop or open a file in Input to see the result here.

Waiting for input
  • ⌘Enter Format
  • ⌘⇧C Copy result
  • ⌘F Find in result
  • Esc Exit full screen
  • Use Ctrl instead of ⌘ on Windows and Linux

How to format SQL

  1. Paste your query into the SQL box, or drop a .sql file on it.
  2. Choose your Dialect, so that database specific syntax is understood.
  3. Pick the keyword case and indent. The formatted query appears on the right. Select Copy or Download to keep it.

The result updates as you type, so you can adjust the options and watch the layout change.

What formatting does

SQL ignores most white space, which means queries are often written on one long line or squeezed together by tools that generate them. The formatter puts each clause on its own line, indents column lists and conditions, and aligns joins and sub-queries so you can see the structure at a glance. It can also make keywords upper case, the common convention, or lower case if your team prefers.

Because formatting only touches whitespace and keyword case, it never changes the result of the query. The formatter reads the query as tokens, so quoted strings and identifiers are left exactly as they are.

Choosing a dialect

Databases add their own syntax. PostgreSQL has :: casts and $1 parameters, MySQL uses backticks for names, SQL Server uses square brackets and TOP, and BigQuery has arrays and structs. If your query uses these, pick the matching dialect. If you are unsure, standard SQL works for most plain queries.

Tips

  • Format a query before you share it in a code review or ticket. People read structured SQL much faster.
  • Use upper case keywords and lower case names so that the two stand apart.
  • When a query returns the wrong rows, formatting often shows the problem, such as an OR that should be inside brackets.
  • Keep long queries in a file and use version control, so changes are easy to compare.
  • Searching logs for table names? The regex tester can help build the pattern, and the cron expression explainer can check the schedule that runs your report.

Your SQL stays in your browser. Nothing is sent to a server.

Questions

Which SQL dialects are supported?

Standard SQL, MySQL, MariaDB, PostgreSQL, SQLite, BigQuery, SQL Server (T-SQL), Oracle PL/SQL, Amazon Redshift and Snowflake.

Does formatting change what the query does?

No. Only whitespace, line breaks and the case of keywords change. Strings, names and values stay as written.

Are my queries uploaded?

No. Formatting runs in your browser, so table names and data in your queries stay on your device.

Why do I get an error?

The formatter could not parse the query. Look for a missing quote or bracket, or choose the dialect that matches your database.

Can I format several statements at once?

Yes. Separate them with semicolons and each statement is formatted with a blank line between them.

More developer tools