csvjson

SQL Formatter

Paste any SQL query and get clean, consistently formatted output. Supports MySQL, PostgreSQL, SQLite, T-SQL, and BigQuery. Configurable indent, keyword case, and style.

Supported dialects

Choose the dialect that matches your database for the most accurate formatting

Generic SQL

ANSI SQL — works for most databases as a baseline.

MySQL / MariaDB

Adds MySQL-specific syntax: backtick identifiers, SHOW, REPLACE INTO.

PostgreSQL

Adds :: casts, $$ dollar quoting, and PostgreSQL-specific functions.

SQLite

Lightweight dialect with PRAGMA support and SQLite type affinity.

T-SQL

SQL Server / Azure SQL syntax: square bracket identifiers, TOP, GO.

BigQuery

Google BigQuery dialect with backtick identifiers and STRUCT/ARRAY.

Before and after

A typical query before and after formatting

Before
select u.id,u.email,count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.status='active' group by u.id,u.email having count(o.id)>0 order by orders desc limit 25
After
SELECT
  u.id,
  u.email,
  COUNT(o.id) AS orders
FROM
  users u
  LEFT JOIN orders o ON o.user_id = u.id
WHERE
  u.status = 'active'
GROUP BY
  u.id,
  u.email
HAVING
  COUNT(o.id) > 0
ORDER BY
  orders DESC
LIMIT
  25

Frequently asked questions

What does an SQL formatter actually do?

It parses the SQL token stream (keywords, identifiers, literals, operators) and reprints them with consistent indentation, line breaks, and keyword casing. The query's logic and meaning are unchanged — only the whitespace and capitalization are adjusted.

Why do SQL keywords get uppercased?

ANSI SQL is case-insensitive for keywords, but uppercase keywords (SELECT, FROM, WHERE) is the dominant convention in most style guides (SQL Style Guide, GitLab, Mozilla). It visually distinguishes keywords from table and column names, making queries easier to scan.

What is tabular indentation style?

In tabular style, clauses align so that all column names or values start at the same horizontal position. For example, SELECT, FROM, and WHERE are right-aligned to form a column of keywords. Some teams prefer this for very dense queries; standard indentation is more common.

Will formatting change the query's behavior?

No. The formatter only changes whitespace and keyword case. SQL is whitespace-insensitive — the query engine sees the same tokens regardless of indentation or line breaks. The formatted query will always produce the same result as the original.

Can I format multiple queries at once?

Yes. Paste multiple queries separated by semicolons and all of them will be formatted. Use the 'Between queries' option to control how many blank lines appear between each statement in the output.

Why does the formatter show an error for my query?

The formatter's parser is stricter than most database engines. Common causes: non-standard vendor syntax the selected dialect doesn't know, incomplete fragments (just a WHERE clause without SELECT/FROM), or queries with custom delimiters like MySQL's DELIMITER $$. Try switching to the correct dialect or use Generic SQL.