PyCharm 2024.3 Help

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, SELECT). The To left with indent option aligns all keywords except for WITH, UNION, and INTERSECT along the left margin with the indent.

  • To left

    To left
  • To left with indent

    To left with indent
  • To right

    To right

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 (,) to the beginning (To begin) or to the end (To end) of a code line.

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 PyCharm. 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.

  • Enabled

    Align section elements is on
  • Disabled

    Align section elements is off

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 INTO and clause elements that follow INTO on a new line.

Place INTO clause elements on

Move clause elements that follow INTO on a new 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.

Place VALUES clause elements (rows) on

Move clause elements that follow VALUES on a new 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.

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.

  • Same line aligned: align all members of the clause, keep the first member on the same line with a parenthesis.

  • Wrapped unindented: move all members of the clause to a new line without adding an indent.

  • Wrapped aligned: align and move all members of the clause to a new line.

  • Wrapped indented: add an indent and move all members of the clause to a new line.

Place the closing parenthesis

Change the position of the closing parenthesis.

  • At the end: place the closing parenthesis at the same line with the last element of a clause.

  • To begin: move the closing parenthesis to a new line with the last element of a clause.

  • Under opening: place the closing parenthesis under the opening parenthesis.

  • Under elements: place the closing parenthesis under aligned elements of a clause.

Wrap columns or values

Move objects to a new line.

  • Chop: move each value to a new line.

  • Chop if long: move each value to a new line if the text exceeds the configured line length. To configure the line length, open settings Ctrl+Alt+S, navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.

  • Wrap if long: break a section of text into lines so that each line fits the configured line length. To configure the line length, open settings Ctrl+Alt+S, navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.

Place comma

Move a comma (,) to the beginning (To begin) or to the end (To end) of a code line.

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.

  • To begin

    To left
  • To end

    To left with indent

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.

  • Enabled

    All statements are placed on a single line
  • Disabled

    Statements are placed on several lines

Align multi-row VALUES

Choose the most suitable width for the VALUES columns. For the values that are much longer than others, move the remaining fields to the next row.

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.

  • Chop: move each value to a new line.

  • Chop if long: move each value to a new line if the text exceeds the configured line length. To configure the line length, open settings Ctrl+Alt+S, navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.

  • Wrap if long: break a section of text into lines so that each line fits the configured line length. To configure the line length, open settings Ctrl+Alt+S, navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.

Place comma

Move a comma (,) to the beginning (To begin) or to the end (To end) of a code line.

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 (=).

  • Enabled

    All equal signs are aligned
  • Disabled

    Equal signs are not aligned

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.

  • Chop: move each value to a new line.

  • Chop if long: move each value to a new line if the text exceeds the configured line length. To configure the line length, open settings Ctrl+Alt+S, navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.

Place comma

Move a comma (,) to the beginning (To begin) or to the end (To end) of a code line.

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.

  • To begin

    To begin
  • In the middle

    In the middle
  • To end

    To end

Align AS

Align all AS keywords.

  • Enabled

    Align all AS keywords feature is enabled
  • Disabled

    Align all AS keywords feature is disabled

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.

  • Chop: move each value to a new line.

  • Chop if long: move each value to a new line if the text exceeds the configured line length. To configure the line length, open settings Ctrl+Alt+S, navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.

  • Wrap if long: break a section of text into lines so that each line fits the configured line length. To configure the line length, open settings Ctrl+Alt+S, navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.

Place comma

Move a comma (,) to the beginning (To begin) or to the end (To end) of a code line.

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 ALL and DISTINCT.

Keep elements on one line if ≤

Set the maximum number of elements on one line.

Use AS

Always use AS for aliases.

Align AS

Align all AS keywords.

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.

  • Chop: move each value to a new line.

  • Chop if long: move each value to a new line if the text exceeds the configured line length. To configure the line length, open settings Ctrl+Alt+S, navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.

  • Wrap if long: break a section of text into lines so that each line fits the configured line length. To configure the line length, open settings Ctrl+Alt+S, navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.

Place comma

Move a comma (,) to the beginning (To begin) or to the end (To end) of a code line.

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 JOIN in the SELECT statement to a new line.

Wrap the next JOIN

Move the second JOIN in the SELECT statement to a new line.

Indent JOIN

Add an indent before the JOIN clause.

Place JOIN in join-only queries under

Select the element according to which you want to align the JOIN clause.

  • Table (as usual): align to the table name.

  • FROM indented: align to the right margin of FROM with an indent.

  • FROM: align to the left margin of FROM.

Align joined tables

Align table names in JOIN clauses.

Align table aliases

Align table aliases in JOIN clauses.

Wrap ON/USING

Move ON and USING to a new line.

Place ON/USING under

Align ON and USING to the table name (Table), or align to the table name and add an indent (Table indented).

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.

  • Chop: move each value to a new line.

  • Chop if long: move each value to a new line if the text exceeds the configured line length. To configure the line length, open settings Ctrl+Alt+S, navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.

  • Wrap if long: break a section of text into lines so that each line fits the configured line length. To configure the line length, open settings Ctrl+Alt+S, navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.

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 AS keywords.

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.

  • Chop: move each value to a new line.

  • Chop if long: move each value to a new line if the text exceeds the configured line length. To configure the line length, open settings Ctrl+Alt+S, navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.

  • Wrap if long: break a section of text into lines so that each line fits the configured line length. To configure the line length, open settings Ctrl+Alt+S, navigate to Editor | Code Style, and type the necessary length in the Hard wrap at N columns field.

Place comma

Move a comma (,) to the beginning (To begin) or to the end (To end) of a code line.

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 ASC and DESC keywords.

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.

  • Same line aligned: align all members of the clause, keep the first member on the same line with a parenthesis.

  • Wrapped unindented: move all members of the clause to a new line without adding an indent.

  • Wrapped aligned: align and move all members of the clause to a new line.

  • Wrapped indented: add an indent and move all members of the clause to a new line.

Place the closing parenthesis

Change the position of the closing parenthesis.

  • At the end: place the closing parenthesis at the same line with the last element of a clause.

  • Unindented: move the closing parenthesis to a new line without an indent.

  • To begin: move the closing parenthesis to a new line with the last element of a clause.

  • Under opening: place the closing parenthesis under the opening parenthesis.

  • Under elements: place the closing parenthesis under aligned elements of a clause.

Put spaces within parentheses

Add a space after the opening parenthesis and before the closing parenthesis.

Last modified: 14 November 2024