Pick the dialect that matches your database
SQL is a standard with many accents. The dialect tells the formatter which words are keywords, how names are quoted, and which operators exist, so it can read your query the way your database would.
- MySQL and MariaDB quote names with backticks, as in
`order`. SQL Server uses square brackets, as in[order]. - PostgreSQL has the
::cast, as inprice::int, and numbered placeholders such as$1. - BigQuery uses backticks around project and table paths.
- Oracle (PL/SQL) and SQL Server (T-SQL) add procedural keywords such as
BEGIN,DECLAREandWHILE.
If you are not sure, start with Standard SQL. If the formatter reports an error on a query that works in your database, switch to the matching dialect before assuming the query is wrong.
How the layout works
Each main clause (SELECT, FROM, WHERE, GROUP BY, ORDER BY) starts on its own line, and the items under it are indented. Select columns go one per line. AND and OR start new lines, either at the start or the end of the line as you choose. Subqueries and CASE expressions are indented as blocks. Several statements are separated by blank lines, and you can set how many.
Short expressions in brackets, such as IN (1, 2, 3) or varchar(50), stay on one line. Under More options you can change how long a bracketed expression may be before it is split. The Aligned layouts line the keywords up in a column.
What the formatter changes and what it does not
It changes white space, and the case of keywords if you ask for it. Keyword case applies to SQL keywords. Function names and text inside quotes are not changed, and neither are most table and column names. A name that is also a keyword in the dialect, such as year, end, user or values, is read as a keyword: it changes case with the Keywords setting, and a word like values can also start a new line. Choose Keep under Keywords to leave every word as you wrote it, or put such a name in quotes. Comments, both -- line and /* block */, are kept.
It does not run your query, rename anything, or reorder clauses. Because it does not know your schema, a misspelled column passes. Run the query on a copy of your data when you need to know that it works.
Procedural code, such as loops and variables in T-SQL or PL/SQL, is read only roughly, so expect a less tidy layout for those blocks.