Why choose a dialect
SQL databases share a core but differ in the details: PostgreSQL uses $1 parameters and :: casts, MySQL quotes identifiers with backticks, SQL Server with [brackets] and has TOP, BigQuery uses backticks for project.dataset.table. Choosing the right dialect makes sure these are recognised as single tokens and formatted correctly. Standard SQL works for most simple queries.
How to use the SQL Formatter
- Paste SQL, or press Sample.
- Choose your database's dialect.
- Choose the keyword case and indentation.
- Copy the result or download it as a .sql file.
Examples
A PostgreSQL report query with uppercase keywords
select u.id,u.name,count(o.id) as orders from users u left join orders o on o.user_id=u.id where u.created_at>=now()-interval '30 days' group by u.id,u.name having count(o.id)>2 order by orders descSELECT
u.id,
u.name,
count(o.id) AS orders
FROM
users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE
u.created_at >= now() - interval '30 days'
GROUP BY
u.id,
u.name
HAVING
count(o.id) > 2
ORDER BY
orders DESC
Function names such as count and now keep their case; only keywords change.
A MySQL update with lowercase keywords
UPDATE `products` SET `price` = `price` * 1.1, `updated_at` = NOW() WHERE `category_id` IN (3, 7) AND `stock` > 0;update `products`
set
`price` = `price` * 1.1,
`updated_at` = NOW()
where
`category_id` in (3, 7)
and `stock` > 0;
SQL Server with 4-space indentation
SELECT TOP 5 [Name], [Total] FROM [dbo].[Orders] WHERE [Status] = N'Shipped' ORDER BY [Total] DESCSELECT
TOP 5 [Name],
[Total]
FROM
[dbo].[Orders]
WHERE
[Status] = N'Shipped'
ORDER BY
[Total] DESC
What changes
Formatting only changes whitespace and, if you choose, the case of keywords. Identifiers, strings, comments and numbers are kept exactly. Each major clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY…) starts a new line, list items and conditions are indented below it, and multiple statements are separated by a blank line.
Options
- Dialect
- The database the SQL is written for: Standard SQL, PostgreSQL, MySQL, MariaDB, SQLite, SQL Server, Oracle, BigQuery, Snowflake, Redshift, Spark, DuckDB or ClickHouse.
- Keywords
- Keep keywords as written, or make them UPPERCASE or lowercase.
- Indent
- 2 spaces (the default), 4 spaces or tabs.
Limitations
- The formatter checks syntax loosely: it can format some invalid SQL, and doesn't validate table or column names.
- Stored procedure bodies and very dialect-specific syntax may be laid out imperfectly.
- Very long queries are kept as one statement; the layout doesn't wrap at a line width.
Frequently asked questions
Is my SQL uploaded?
No. Formatting happens in your browser. That matters, because queries often contain table names, customer data or credentials.
Does formatting change what my query does?
No. Only whitespace and, if you choose, keyword case change. SQL keywords aren't case-sensitive, and identifiers and strings are kept exactly.
Why is there a parse error when my query runs fine?
Usually the dialect: syntax such as $1, backticks or TOP is only valid in some databases. Choose your database's dialect and try again.