How to format SQL safely and read the result
This formatter is for developers, analysts, students, and anyone who receives a dense query and needs a clearer version before review. It changes whitespace and, if requested, keyword letter case. It does not connect to a database, validate a schema, optimize a query, or prove that the query is correct.
How to use the SQL formatter
- Paste one query or a short SQL script into the input. Choose the dialect that matches the database that will eventually run the code. Standard SQL is a practical fallback for common SELECT, INSERT, UPDATE, and DELETE statements, but it is not automatic dialect detection. Pick PostgreSQL, MySQL, MariaDB, SQLite, BigQuery, SQL Server, or Snowflake when the query uses features specific to that system.
- Choose two or four spaces and decide whether recognized keywords should become uppercase, lowercase, or keep their original case. Select Format SQL or press Ctrl/Command+Enter. The output appears beside the input on a wide screen and below it on a narrow screen. Read the message, review the code, then copy the result. Editing the input or an option marks the previous output as out of date until you format again.
What formatting changes—and what it preserves
The formatter tokenizes the query, places major clauses such as SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, and LIMIT on readable lines, and indents nested expressions. Keyword case affects recognized SQL keywords only. Identifiers, quoted identifiers, numbers, operators, string contents, line comments, block comments, and supported placeholders remain data rather than instructions to rewrite their meaning.
Formatting is not a semantic proof. Whitespace can matter inside quoted strings, vendor-specific bodies, and template languages. This page uses the maintained sql-formatter library and exposes a limited, predictable set of options. It does not substitute parameter values. Common placeholders such as ?, :name, $1, and @name are kept when supported by the selected dialect. Always compare critical migrations, stored procedures, or generated SQL with the original before running it.
Choose the dialect before blaming the query
SQL products share a core language but disagree on quoting, functions, procedural blocks, operators, data types, and statement syntax. PostgreSQL dollar-quoted strings, BigQuery backtick paths and QUALIFY, SQL Server brackets and TOP, MySQL backticks and LIMIT, and Snowflake-specific clauses are examples of why the dialect setting matters. The Standard SQL option supports a useful common subset; it does not discover the database from the text.
If formatting fails, keep the input, select the actual target dialect, and try again. If the query contains application templates such as {{ column }} or custom macros, replace them temporarily with placeholders accepted by your database or format the surrounding SQL in smaller pieces. Do not remove a template marker blindly: it may be required by the application even though it is not SQL.
Use the output in reviews and editors
Copy the formatted result into a scratch file or version-control diff and review structure before changing logic. Consistent clause breaks make missing join conditions, unexpected AND/OR grouping, and duplicated expressions easier for a person to notice, but the formatter does not lint for those problems. A clean layout is a reading aid, not approval to deploy.
The output is plain text. There is no account, history, download, share link, database connection, or cloud storage. Keep your original in source control or another trusted location. Closing or refreshing the tab loses the text. Because processing stays in the browser, this page does not intentionally send pasted SQL through a formatting API; common site analytics must never include the SQL input.
Two concrete formatting examples
Join, string, comment, and named placeholder
With PostgreSQL selected and uppercase keywords, the clauses become visible while the string, comment, and :minimum placeholder remain unchanged.
select u.id,u.name from users u -- active accounts
join orders o on o.user_id=u.id where u.status='active user' and o.total>:minimum order by o.created_at desc;Positional placeholder and nested query
A PostgreSQL $1 placeholder stays a placeholder. The nested SELECT is indented; the tool does not contact PostgreSQL or check whether the table exists.
select * from events where account_id=$1 and created_at>(select max(created_at) from archive);Limits and common errors
- Maximum input is 100,000 characters so one accidental generated file cannot freeze the page indefinitely. Split larger scripts at statement boundaries.
- An empty input is rejected without clearing it. A parsing error also keeps the original text so you can change the dialect or template syntax.
- The formatter does not execute SQL, inspect tables, check permissions, lint unsafe UPDATE or DELETE statements, optimize indexes, or convert between dialects.
- Comments and strings are intended to be preserved, but unsupported vendor syntax, procedural code, or templates still require manual comparison.
- Copy uses the browser clipboard. If permission is unavailable, select the visible plain-text output and copy it manually.
Frequently asked questions
Is my SQL uploaded or executed?
No. Formatting runs in this browser tab. The page does not connect to a database or run the query. Do not confuse that with a guarantee about every browser extension or device you use.
Which dialect should I choose?
Choose the database that will run the query. Use Standard SQL only for common syntax or when the target is genuinely unknown, then review vendor-specific parts manually.
Will comments, strings, and placeholders survive?
Supported comments, quoted strings, and common placeholders are tokens and are preserved. Check templates and procedural SQL carefully because unsupported syntax can fail.
Does formatting make a query safe or faster?
No. It changes presentation. Authorization, parameters, transaction safety, query plans, indexes, and production review are separate tasks.
Why did formatting fail?
The most common causes are the wrong dialect or template/vendor syntax outside the library’s supported grammar. Keep the input, select the correct dialect, and isolate the unsupported portion.