Queries
Configure code style for INSERT
, UPDATE
, WITH
, SELECT
, FROM
, and other query structures.
Use this page to configure formatting options for SQL files. When you change these settings, the Preview pane shows how this will affect your code.
Common
Item | Description |
---|---|
Align the first word of clause | Align keywords to the left or right margin of the first word of a statement section (for example,
|
Place clause elements on | Move clause elements to a new line (New line) or leave them on the same line (Same line). |
Place comma | Move a comma ( The Auto option analyzes the surrounding context and calculates the most suitable place for a comma. For example, you have three occurrences of a comma: two commas go at the beginning, one comma is at the end. The Auto option will move the third occurrence of the comma to the beginning. This option works only if you have more than three cases in a single context. Otherwise, commas are left as is. If you want to disable a new line after the comma when the To begin option is enabled, clear the Line breaks checkbox on the Wrapping tab. |
Collapse short statements | Join multiline short statements. The length of a statement that will be collapsed is determined automatically by DataGrip. To enable this option only for subqueries, select Subqueries only. |
Keep section elements under section header | Move all section elements under the section main keyword (a header). |
Align section elements | Align elements of a clause section.
|
Align line comments at right of elements | Align line comments that are on the right side of code. |
INSERT statement and VALUES clause
Item | Description |
---|---|
Place INTO on the new line | Move |
Place INTO clause elements on | Move clause elements that follow The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab. |
Place VALUES clause elements (rows) on | Move clause elements that follow The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab. |
Place the opening parenthesis | Align or indent the opening parenthesis under the first keyword on the line. Select On the same line to keep the opening parenthesis on the line with the keyword. |
Place columns or values | Change the position of elements in relation to the opening parenthesis.
|
Place the closing parenthesis | Change the position of the closing parenthesis.
|
Wrap columns or values | Move objects to a new line.
|
Place comma | Move a comma ( The Auto option analyzes the surrounding context and calculates the most suitable place for a comma. For example, you have three occurrences of a comma: two commas go at the beginning, one comma is at the end. The Auto option will move the third occurrence of the comma to the beginning. This option works only if you have more than three cases in a single context. Otherwise, commas are left as is. If you want to disable a new line after the comma when the To begin option is enabled, clear the Line breaks checkbox on the Wrapping tab.
The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab. . |
Put spaces within parentheses | Add a space after the opening parenthesis and before the closing parenthesis. |
Collapse short multi-row values | Place all statements on a single line.
|
Align multi-row VALUES | Choose the most suitable width for the |
UPDATE statement
Item | Description |
---|---|
Place elements on | Move clause elements to a new line (New line) or leave them on the same line (Same line). The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab. |
Wrap elements | Move elements to a new line.
|
Place comma | Move a comma ( The Auto option analyzes the surrounding context and calculates the most suitable place for a comma. For example, you have three occurrences of a comma: two commas go at the beginning, one comma is at the end. The Auto option will move the third occurrence of the comma to the beginning. This option works only if you have more than three cases in a single context. Otherwise, commas are left as is. If you want to disable a new line after the comma when the To begin option is enabled, clear the Line breaks checkbox on the Wrapping tab. The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab. |
Align `=` | Align all equal signs (
|
WITH clause
Item | Description |
---|---|
Place elements on | Move clause elements to a new line (New line) or leave them on the same line (Same line). The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab. |
Wrap subqueries | Move elements to a new line.
|
Place comma | Move a comma ( The Auto option analyzes the surrounding context and calculates the most suitable place for a comma. For example, you have three occurrences of a comma: two commas go at the beginning, one comma is at the end. The Auto option will move the third occurrence of the comma to the beginning. This option works only if you have more than three cases in a single context. Otherwise, commas are left as is. The In the middle option joins two lines of code on one line. If you want to disable a new line after the comma when the To begin option is enabled, clear the Line breaks checkbox on the Wrapping tab. The Place comma option works only if the Wrap subqueries option in the WITH clause section is set to Chop or Chop if long. The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab.
|
Align AS | Align all
|
SELECT clause
Item | Description |
---|---|
Place elements on | Move clause elements to a new line (New line) or leave them on the same line (Same line). The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab. |
Wrap elements | Move elements to a new line.
|
Place comma | Move a comma ( The Auto option analyzes the surrounding context and calculates the most suitable place for a comma. For example, you have three occurrences of a comma: two commas go at the beginning, one comma is at the end. The Auto option will move the third occurrence of the comma to the beginning. This option works only if you have more than three cases in a single context. Otherwise, commas are left as is. If you want to disable a new line after the comma when the To begin option is enabled, clear the Line breaks checkbox on the Wrapping tab. The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab. |
New line after ALL, DISTINCT | Add a new line after |
Keep elements on one line if ≤ | Set the maximum number of elements on one line. |
Use AS | Always use |
Align AS | Align all |
FROM clause
Item | Description |
---|---|
Place elements on | Move clause elements to a new line (New line) or leave them on the same line (Same line). The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab. |
Wrap elements | Move elements to a new line.
|
Place comma | Move a comma ( The Auto option analyzes the surrounding context and calculates the most suitable place for a comma. For example, you have three occurrences of a comma: two commas go at the beginning, one comma is at the end. The Auto option will move the third occurrence of the comma to the beginning. This option works only if you have more than three cases in a single context. Otherwise, commas are left as is. If you want to disable a new line after the comma when the To begin option is enabled, clear the Line breaks checkbox on the Wrapping tab. The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab. |
Wrap the first JOIN | Move the first |
Wrap the next JOIN | Move the second |
Indent JOIN | Add an indent before the |
Place JOIN in join-only queries under | Select the element according to which you want to align the
|
Align joined tables | Align table names in |
Align table aliases | Align table aliases in |
Wrap ON/USING | Move |
Place ON/USING under | Align |
WHERE and HAVING clauses
Item | Description |
---|---|
Place elements on | Move clause elements to a new line (New line) or leave them on the same line (Same line). The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab. |
Wrap elements | Move elements to a new line.
|
Place top-level AND/OR | Move AND and OR to the end (To end) or to the beginning (To begin) of a clause. |
Align AS | Align all |
GROUP BY and ORDER BY clauses
Item | Description |
---|---|
Place elements on | Move clause elements to a new line (New line) or leave them on the same line (Same line). The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab. |
Wrap elements | Move elements to a new line.
|
Place comma | Move a comma ( The Auto option analyzes the surrounding context and calculates the most suitable place for a comma. For example, you have three occurrences of a comma: two commas go at the beginning, one comma is at the end. The Auto option will move the third occurrence of the comma to the beginning. This option works only if you have more than three cases in a single context. Otherwise, commas are left as is. If you want to disable a new line after the comma when the To begin option is enabled, clear the Line breaks checkbox on the Wrapping tab. The As in common option means that the behavior of the selected option must duplicate the behavior of the analogous option in the Common section on the Queries tab. |
Align ASC/DESC | Align all |
Subquery
Item | Description |
---|---|
Place the opening parenthesis | Align or indent the opening parenthesis under the first keyword on the line. Select On the same line to keep the opening parenthesis on the line with the keyword. |
Place subquery | Change the position of elements in parentheses.
|
Place the closing parenthesis | Change the position of the closing parenthesis.
|
Put spaces within parentheses | Add a space after the opening parenthesis and before the closing parenthesis. |