Specifies the SQL dialect to use.
import { format } from 'sql-formatter';
const result = format('SELECT * FROM tbl', { dialect: 'sqlite' });
"sql"
- (default) Standard SQL"bigquery"
- GCP BigQuery"db2"
- IBM DB2"db2i"
- IBM DB2i (experimental)"hive"
- Apache Hive"mariadb"
- MariaDB"mysql"
- MySQL"tidb"
- TiDB"n1ql"
- Couchbase N1QL"plsql"
- Oracle PL/SQL"postgresql"
- PostgreSQL"redshift"
- Amazon Redshift"singlestoredb"
- SingleStoreDB"snowflake"
- Snowflake"spark"
- Spark"sqlite"
- SQLite"transactsql"
or"tsql"
- SQL Server Transact-SQL"trino"
- Trino (should also work for Presto, which is very similar dialect, though technically different)
The default "sql"
dialect is meant for cases where you don't know which dialect of SQL you're about to format.
It's not an auto-detection, it just supports a subset of features common enough in many SQL implementations.
This might or might not work for your specific dialect.
Better to always pick something more specific if possible.
Using the language
option has the downside that the used dialects are determined at runtime
and therefore they all have to be bundled when e.g. building a bundle with Webpack.
This can result in significant overhead when you only need to format one or two dialects.
To solve this problem, version 12 of SQL Formatter introduces a new API, that allows explicitly importing the dialects. See docs for dialect option.