SQL Formatter
Rewrite SQL queries with consistent indentation and uppercase or lowercase keywords for common dialects.
Your data stays in your browser. This tool processes your input locally and does not upload it to a server.
Input
Output
What does a SQL formatter do?
A SQL formatter rewrites a query with consistent line breaks, indentation and keyword case without changing what it does. Long one-line statements become readable clauses. FestivKit formats Standard SQL, MySQL, PostgreSQL, MariaDB, SQLite, T-SQL and PL/SQL in your browser, and also minifies queries to a single line.
How formatting works
The tool uses the open-source sql-formatter library. It tokenizes the query for the dialect you pick, then puts major clauses such as SELECT, FROM, WHERE and ORDER BY on their own lines. Columns, joins and conditions are indented beneath them.
You can set the indent to 2 spaces, 4 spaces or tabs, and choose uppercase or lowercase keywords. Only layout and keyword case change. Identifiers, string values and the logic of the query stay the same.
Choosing a dialect
Dialects differ in quoting, operators and reserved words. PostgreSQL uses double quotes for identifiers and :: for casts. MySQL uses backticks. T-SQL uses [brackets] and TOP. Pick the dialect that matches your database so these are tokenized correctly.
If a query fails to parse, the tool shows a short error. Try another dialect or check for an unbalanced parenthesis or quote.
Minify and privacy
Minify strips comments and collapses whitespace to single spaces while leaving quoted strings and quoted identifiers untouched. Queries are processed locally and are not uploaded, which suits queries that mention internal table names.
Examples
Format with Standard SQL, 2 spaces, uppercase keywords
Input
select id, name, created_at from tools where popular = true and category = 'formatters' order by name ascOutput
SELECT
id,
name,
created_at
FROM
tools
WHERE
popular = TRUE
AND category = 'formatters'
ORDER BY
name ASCFormat a join with PostgreSQL
Input
select u.id, count(o.id) as orders from users u left join orders o on o.user_id = u.id where u.active = 1 group by u.idOutput
SELECT
u.id,
count(o.id) AS orders
FROM
users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE
u.active = 1
GROUP BY
u.idFunction names such as count are left in their original case.
Minify
Input
select *
from t -- all rows
where name = 'a b'Output
select * from t where name = 'a b'The comment is removed. The double space inside the string is kept.
Common mistakes and edge cases
- Pick the matching dialect. A PostgreSQL query formatted as MySQL may mis-handle quotes or operators and fail to parse.
- Formatting does not validate against your schema. A query can format cleanly and still reference a missing column.
- Minify removes comments, including optimizer hints written as comments such as /*+ ... */. Do not minify queries that depend on them.
- Keyword case is cosmetic. Changing it never alters how the database runs the query, and the tool leaves identifiers alone because they can be case-sensitive.
- Stored procedures and vendor-specific syntax may not parse in every dialect. Format one statement at a time if you get an error.
How to use this tool
- Paste a SQL query.
- Pick a dialect, indentation, and keyword case.
- Format or minify, then copy the query.
Frequently asked questions
Which SQL dialects does the formatter support?
It supports Standard SQL, MySQL, PostgreSQL, MariaDB, SQLite, T-SQL (SQL Server) and PL/SQL (Oracle). The dialect controls how identifiers, quotes, operators and reserved words are recognised. Choose the one that matches your database. If you are unsure, start with Standard SQL and switch if the tool reports a parse error.
Does formatting SQL change what the query does?
No. Formatting changes whitespace, line breaks and keyword case only. The tokens, values, order of clauses and string literals stay the same, so the database executes the same statement. You should still review output before running anything that modifies data, as with any pasted query.
Should SQL keywords be uppercase or lowercase?
Both work identically in every major database. Uppercase keywords are a long-standing convention because they separate keywords from table and column names at a glance. Many teams now prefer lowercase for ease of typing. Pick one style for your team, set it here, and apply it consistently.
Is my SQL sent to a server?
No. Formatting and minifying run in your browser using JavaScript. The query text is not uploaded or stored by FestivKit. That makes it reasonable for queries with internal table names, though you should still avoid pasting real credentials or personal data into any tool.
Why do I get a SQL formatting error?
The parser could not understand part of the query for the selected dialect. Common causes are an unclosed parenthesis or quote, a missing comma, or syntax that belongs to another dialect. Check the position named in the message, then try a different dialect. Formatting a single statement at a time also helps isolate the problem.
References
Last reviewed