csvjson

SQL Formatter

Format and beautify SQL queries. Supports MySQL, PostgreSQL, SQLite, T-SQL, and BigQuery with configurable indent and keyword case.

๐Ÿ”ง

SQL Formatter is coming soon. In the meantime, try the JSON โ†’ CSV converter, which has flattening built in.

How it works

Dialect-aware token parsing

The formatter parses the SQL token stream for the selected dialect, recognising vendor-specific keywords (like MySQL's REPLACE INTO or T-SQL's square bracket identifiers). This produces more accurate formatting than a generic regex-based approach.

Configurable output

Control indent width (2 or 4 spaces), keyword case (UPPERCASE or preserve), and indent style (standard or tabular). Multiple statements separated by semicolons are all formatted in one pass.

Example

Formatting a minified analytics query before adding to documentation

Input
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 order by orders desc limit 25
Output
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
ORDER BY
  orders DESC
LIMIT
  25

Keywords are uppercased, each clause starts on a new line, and SELECT columns are individually indented.

Frequently asked questions

Will formatting change my query's behavior?

No. The formatter only changes whitespace and keyword case. SQL is whitespace-insensitive โ€” the query engine sees identical tokens before and after formatting.

Which dialects are supported?

Generic SQL, MySQL, PostgreSQL, SQLite, T-SQL (SQL Server / Azure SQL), and BigQuery. Choose the dialect that matches your database for the most accurate keyword recognition.