English

SQL Formatter — Beautify and Indent Queries

Beautify SQL (MySQL, PostgreSQL and other dialects, keyword case, indentation)

Runs in your browser · nothing is uploaded

Keyword case
Indentation

Formatted SQL

What it is

A query pasted from a log or an ORM often arrives as one long line, or with inconsistent indentation, which is hard to read and review. This tool breaks SQL into clauses such as SELECT, FROM and WHERE and indents it consistently. The result updates as you type.

How to use

  1. Paste your SQL into the input. Several statements separated by semicolons are fine.
  2. Choose the dialect that matches your database.
  3. Pick uppercase, lowercase or keep keywords as typed.
  4. Choose 2 spaces, 4 spaces or tab indentation and copy the result.

How it works

  • Formatting is done by the open-source sql-formatter library. It splits the input into tokens, then decides line breaks and indentation from clause and parenthesis depth.
  • Supported dialects are Standard SQL, MySQL, PostgreSQL, MariaDB, SQLite, BigQuery, Oracle (PL/SQL) and SQL Server (T-SQL). The dialect changes how identifier quotes (`, ", [ ]), parameter markers (?, $1, @name) and operators are read.
  • MyBatis placeholders #{id}, #{name,jdbcType=VARCHAR} and ${table} are kept as they are in every dialect. In MySQL # normally starts a comment, but #{ is treated as a placeholder. A placeholder spread over several lines is kept too; nested braces such as #{list[${i}]} are not supported.
  • Bind parameters: ? and :name in Standard SQL, MySQL and MariaDB; $1 and :name in PostgreSQL; :name in Oracle; @name in SQL Server and BigQuery; SQLite accepts ?, ?1, :name, @name and $name.
  • Errors name the line, column and text where parsing stopped.
  • The keyword case option applies to reserved words only. String literals, comments and identifiers, including table and column names in Korean, are not altered.
  • The tab option uses one tab character per indent level.
  • It only reformats. It does not run the query or check what it means.

Examples

Input:

select id, name from users where age > 20 and city = '서울' order by name

Result (Standard SQL, uppercase, 2 spaces):

SELECT
  id,
  name
FROM
  users
WHERE
  age > 20
  AND city = '서울'
ORDER BY
  name

FAQ

Is my query sent to a server?

No. Formatting runs in your browser with the sql-formatter library, and queries are neither transmitted nor stored. Still, avoid showing queries that contain real passwords or personal data on a shared screen.

Which dialect should I choose?

Pick the database you use. Then dialect-specific syntax is recognized correctly, such as MySQL backticks, PostgreSQL `::` casts and `$1` parameters. If you are unsure, start with Standard SQL.

Can formatting change what my query does?

Only whitespace, line breaks and keyword case change. String literals, comments and identifiers keep their content, and changing keyword case never touches values inside quotes, so the query behaves the same.

What if it reports an error?

An unclosed quote or a symbol the chosen dialect does not support can stop the parser. Check the spot named in the message or try another dialect. This is a formatter, not a validator, so it will not catch every mistake in your SQL.

Missing a tool?