PyCharm 2017.3 Help

Code Style. SQL

File | Settings | Editor | Code Style | SQL for Windows and Linux
PyCharm | Preferences | Editor | Code Style | SQL for macOS
Ctrl+Alt+S settings


Use this page to configure formatting options for SQL files. View the result in the Preview pane on the right.

General

Use this tab to specify certain formatting behaviors in your code. The results are displayed in the Preview pane.

ItemDescription
Word CaseIn this node, specify whether the keywords, identifiers, or quoted identifiers case should change automatically. Click the right-hand column, and check the desired behavior on the menu to turn it on.

The possible options are:

  • To upper: the elements are automatically converted to the upper case.
  • To lower: The elements are automatically converted to lower case.
  • Do not change: The case of elements is left as is.
Identifier quotationsClick the right-hand column, and check the desired behavior on the menu to turn it on.

The possible options are:

  • Quote: the identifiers are automatically quoted.
  • Unquote: The identifiers are automatically unquoted.
  • Do not change: The identifiers are left as is.
New line before/afterUse these nodes to define how many blank lines you want PyCharm to retain and insert in your code after reformatting. For each type of SQL element, select of clear the checkbox to the right. The results are highlighted in the Preview pane.
New line around semicolonUse this checkbox to manage line delimiters around a semicolon.
AlignmentSelect the checkboxes next to the desired elements of source code to have them automatically aligned.

Tabs and Indents

ItemDescription
Use tab character
  • If this checkbox is selected, tab characters are used:
    • On pressing the Tab key
    • For indentation
    • For code reformatting
  • When the checkbox is cleared, PyCharm uses spaces instead of tabs.
Smart tabs
  • If this checkbox is selected, the part of indentation defined by the nesting of code blocks, is made of the tabs and (if necessary) spaces, while the part of indentation defined by the alignment is made only of spaces.
  • If this checkbox is cleared, only tabs are used. This means that a group of spaces that fits the specified tab size is automatically replaced with a tab, which may result in breaking fine alignment.

The Smart Tabs checkbox is available if the Use Tab Character checkbox is selected.

Tab sizeIn this text box, specify the number of spaces included in a tab.
IndentIn this text box, specify the number of spaces (or tabs if the Use Tab Character checkbox is selected) to be inserted for each indent level.
Continuation indentIn this text box, specify the number of spaces (or tabs if the Use Tab Character checkbox is selected) to be inserted between the elements of an array, in expressions, method declarations and method calls.
Keep indents on empty linesIf this checkbox is selected, then PyCharm will keep indents on the empty lines as if they contained some code.
If this checkbox is not selected, PyCharm will delete the tab characters and spaces.

Spaces

Use this tab to specify where you want spaces in your code. To have PyCharm automatically insert a space at a location, select the checkbox next to this location in the list. The results are displayed in the Preview pane.

Wrapping and Braces

In this tab, customize the code style options, which PyCharm will apply when reformatting the source code. The left-hand pane contains the list of exceptions (Keep when reformatting), and placement and alignment options for the various code constructs (lists, statements, operations, annotations, etc.). The right-hand pane shows preview.

Alignment takes precedence over indentation options.

ItemDescription
Keep When ReformattingUse the checkboxes in this node to configure exceptions that PyCharm will make when reformatting the source code. For example, by default, the Line brakes checkbox is selected. If your code contains lines that are shorter than a standard convention, you can convert them by disabling the Line brakes check box before you reformat the source code.
Wrap insideUse this node to define wrapping style for the lengthy elements.
You can use different wrapping style options that are available from the drop-down list in the left-hand pane.
Values expressionUse this option to define wrapping style for values expressions. You can use different wrapping style options that are available from the drop-down list in the left-hand pane.
Wrapping Style Options The wrapping style applies to the various code constructs, specified in the left-hand pane (for example, expressions, or assignment statements).
From the drop-down list, select the desired wrapping style:
  • Do not wrap - when this option is selected, no special wrapping style is applied.
  • Wrap if long - select this option to have lines going beyond the right margin wrapped with proper indentation.
  • Chop down if long - select this option to have elements in lists that go beyond the right margin wrapped so that there is one element per line with proper indentation.
  • Wrap always - select this option to have all elements in lists wrapped so that there is one element per line with proper indentation.

Blank Lines

Use this tab to insert blank lines into your code.

ItemDescription
Keep Maximum Blank LinesUse this area to specify blank lines in your code.
Use In code field to enter the number of lines you want to insert. The default number is 2.

Code Generation

The tab contains templates for the names of primary and foreign key constraints, and indexes. These templates are used to generate default names for the constraints and indexes when you create them in the Create Table or the Modify Table dialog.

The templates can contain variables (e.g. {table}) and text. When generating a name, the specified text is reproduced literally.

To get the info about the variables and how you should use them, place the cursor into the field of interest and press Ctrl+Q.

{columns} and {ref_columns}, depending on the situation, are the name of the column, or a list where the column names are separated with the underscore (_).

{unique?u:} checks if the index is unique (unique?), and, if it is, inserts the sequence of characters specified between ? and : (in this example, it's u). If the index is not unique, the sequence between : and } is inserted (in this example, it's nothing).

Example. Using the template {table}_{columns}_{unique?u:}index, you are creating an index on the columns FirstName and LastName in the table persons. If the index is unique, its name, by default, will be persons_FirstName_LastName_uindex. If the index is not unique, its name will be persons_FirstName_LastName_index.

Set from...

Click this link to reveal the list of languages to be used as the base for the current language code style. So doing, only the settings that are applicable to the current language are taken. All the other settings are not affected.

This link appears in the upper-right corner of the language-specific code style page, when applicable.

Click Reset to discard changes and return to the initial set of code style settings.

Last modified: 28 March 2018

See Also