Custom format SQL statements
This feature is in Public Preview.
This article explains how to customize SQL auto-formatting options in the Databricks UI.
Overview
SQL formatting improves the readability and maintainability of your queries. By standardizing indentation, keyword casing, and other stylistic preferences, a well-formatted query is easier to understand, debug, and share with your team.
In Databricks, you can configure formatting options using a .dbsql-formatter-config.json
file saved in your workspace home directory. After saving the file, your SQL code is automatically formatted based on your preferences when you run or format code in the editor or a SQL notebook.
How to configure SQL formatting settings
To configure your personal SQL formatting options:
- Click
Workspace in the sidebar.
- Click Create > File.
- Name the file
.dbsql-formatter-config.json
. - Add your desired settings as key-value pairs in JSON format. See Formatter options
- To apply the latest formatting settings, refresh the page.
Example configuration file
The following example shows a valid .dbsql-formatter-config.json
configuration.
{
"printWidth": 80,
"indentationStyle": "spaces",
"indentationWidth": 4,
"keywordCasing": "uppercase",
"shouldExpandExpressions": true
}
Formatter options
The following table lists the supported configuration options.
Option | Config file name | Allowed values | Default | Description |
---|---|---|---|---|
Print width |
| Any integer >= 0 |
| Sets the target line width for formatted code. |
Indentation style |
|
|
| Specifies whether to use spaces or tabs for indentation. If set, |
Indentation width |
| Integer from 0 to 99 |
| Number of spaces used when |
Keyword casing |
|
|
| Controls formatting of SQL keywords. |
Function name casing |
|
|
| Controls formatting of SQL function names. |
Comma placement |
|
|
| Controls where commas are placed in lists. |
Line breaks between statements |
| Integer from 0 to 99 |
| Number of new lines inserted between statements. |
Line breaks between clauses |
| Integer from 0 to 99 |
| Number of new lines inserted between clauses within a statement. |
Expand boolean expressions |
|
|
| Expands boolean expressions onto separate lines. |
Expand CASE statements |
|
|
| Expands each clause in a CASE statement onto its own line. |
Expand IN lists |
|
|
| Expands items in IN lists onto separate lines. |
Expand BETWEEN conditions |
|
|
| Expands BETWEEN conditions onto separate lines. |
Break JOIN conditions |
|
|
| Breaks JOIN conditions onto separate lines. |