SQL Formatter

Readable SQL for PostgreSQL, MySQL, SQL Server, BigQuery and more.

Runs in your browser Instant No sign-up
Keywords
Indent
SQL
Formatted SQL

Paste, type or drop a file — output appears as you type.

Waiting for input
Processed locally · nothing is uploadedProcessed locally

How to use the SQL formatter

  1. Paste, drop or open one or more SQL statements in the left pane.
  2. Choose the Dialect: Standard SQL, PostgreSQL, MySQL, MariaDB, SQL Server (T-SQL), Oracle PL/SQL, SQLite, BigQuery, Snowflake, Redshift, Spark SQL, Trino / Presto, DuckDB, ClickHouse or IBM Db2.
  3. Choose Keywords: UPPER, lower or Keep (leave them as typed).
  4. Choose Indent: 2 spaces, 4 spaces or Tabs.

Formatting uses the open-source sql-formatter library.

Example

select id,name from users where status='active' and created_at>$1 order by name

With Dialect set to PostgreSQL:

SELECT
  id,
  name
FROM
  users
WHERE
  status = 'active'
  AND created_at > $1
ORDER BY
  name

Each clause starts on its own line, the columns and conditions are indented under it, and AND and OR begin new lines so long WHERE clauses are easy to scan. With Keywords set to lower, the same query uses select, from and and.

Dialect differences

Dialect Quoted identifier Placeholder
PostgreSQL "order" $1
MySQL, MariaDB `order` ?
SQL Server (T-SQL) [order] @p1
Oracle PL/SQL "ORDER" :name

For example, select [order] from [dbo].[t] where id=@p1 formats cleanly as SQL Server (T-SQL) and keeps both the brackets and @p1.

Multiple statements

insert into t (a,b) values (1,2); update t set a=3 where b=2

With MySQL selected, the two statements are formatted separately with a blank line between them, and the status bar reads Formatted 2 statements · mysql.

Errors

When a statement can’t be parsed, the error and its position are shown. select * from t where (a = 1 reports Parse error at token: «EOF» at line 1, column 29 — the closing parenthesis is missing. Errors for valid syntax usually mean the wrong dialect is selected.

Tips

  • Format queries before pasting them into a pull request or a ticket; one clause per line makes review comments precise.
  • Comments are kept: -- note stays on its own line and /* inline */ stays next to its column.
  • Use Keep under Keywords when your team writes lowercase SQL on purpose and you only want indentation fixed.

Doing it locally

npx sql-formatter -l postgresql query.sql

Frequently asked questions

Is my SQL uploaded?

No. Formatting runs in your browser and nothing is uploaded, so queries that mention internal tables and data stay private.

Why does the dialect matter?

Dialects differ in syntax the formatter must recognize: identifier quoting ([name] in SQL Server, backticks in MySQL), placeholders ($1, ?, @p1, :name), operators and keywords. Picking the right dialect avoids parse errors and keeps those tokens intact.

Does formatting validate my query?

Only its syntax. The formatter doesn't know your tables and columns, so a misspelled column or a missing GROUP BY column formats fine. Run the query or EXPLAIN it against your database to validate it.

Can I format several statements at once?

Yes. Statements separated by semicolons are formatted one after another with a blank line between them, and the status bar shows how many were formatted.

Are comments preserved?

Yes. Both -- line comments and /* block */ comments are kept in the output.

Last updated