select a,b from t where x=1 and y=2 goes in, and eight short, indented lines come out. That is all an SQL formatter does, and it saves a lot of squinting at a 400-character query that someone pasted into a ticket. This one covers 20 dialects, from standard SQL to PostgreSQL, MySQL, BigQuery and T-SQL.
Paste, pick a dialect, read the result
- Paste your query into SQL input. The sample holds a join with a subquery, an
INSERTand anUPDATE. - Choose the Dialect. The default is Standard SQL.
- Set Keyword case, Indent and the other options. Every change formats again at once.
- Wait about 300 ms after you type, or press Format.
- Press Copy, or Download .sql to save a file named
formatted.sql.
Why a query fails in the wrong dialect
Standard SQL does not know the PostgreSQL cast a::int, and it does not read the T-SQL name [dbo].[orders]. The formatter then stops with a parse error and the position of the bad token. Switch to PostgreSQL or SQL Server and the same text formats fine.
The error box shows the message of the library and a hint to change the dialect.
Placeholders: ?, $1, :name, @name
Prepared statements contain placeholders. Standard SQL rejects :name, @name and $1 until you pick a style. If the error points at one, open Placeholder style and choose the style your driver uses. All styles accepts all four at once. The placeholders stay in the text. Nothing is replaced with a value.
Layout options for keywords, operators and AND / OR
Keywords become upper case, lower case or stay as typed. Indent is 2 spaces, 4 spaces or a tab. Expression width (50, 80 or 120 characters) decides how long a parenthesized expression may stay on one line. You can put 1 or 2 blank lines between queries, remove the spaces around operators (a=b) and put AND and OR at the start or the end of a line.
What the formatter will not do
It changes whitespace and keyword case. It does not run the SQL, does not know your tables and does not tell you whether the query is correct. Comments stay where they are, and text inside string literals is never touched. To keep one block as it is, wrap it in /* sql-formatter-disable */ and /* sql-formatter-enable */. The library does not support stored procedures or a delimiter other than ;.
Input above 2,000,000 characters is refused with a message.
Where your SQL goes
Nowhere. The formatting library is part of the page code, and it runs in your browser. Formatting sends no request, which you can confirm in the network panel of your browser. Copy uses the clipboard, and Download .sql writes a file on your own device.