PyCharm 2024.3 Help

Query execution

This topic describes the available settings for a query execution. For more information about running queries and viewing the results in PyCharm, refer to the following topics:

  • For more information about running queries, refer to the Run queries topic.

    Run a query
  • Learn how to view the query result in the Query results topic.

    The results of the SELECT statements in the tabs of Services tool window

Item

Description

When caret inside statement execute

If the caret is inside a statement, perform the following actions:

  • Ask what to execute: display a popup where you can select what part of a statement or statements to execute.

    Ask what to execute
  • Smallest subquery or statement: execute the smallest subquery or statement from the script. For example, when the caret is inside a subquery, the whole statement is executed, including a subquery.

    Execute the smallest subquery or statement
  • Smallest statement: execute the smallest statement from the script. For example, when the caret is inside a subquery, the subquery is executed.

    Execute the smallest statement
  • Largest statement: execute the largest statement from the script. For example, when the caret is inside a subquery, an outer statement is executed.

    Execute the largest statement
  • Largest statement or batch: execute the largest statement or a batch of statements from the script. For Transact-SQL (SQL Server and Sybase), the current batch of statements is executed. For all other dialects, the same as the previous option.

  • Whole script: execute the whole script.

    Execute the whole script
  • Everything from caret: execute everything below the caret.

    Execute everything below the caret

When caret outside statement execute

If the caret is outside a statement (for example, on a blank line or within a comment), perform one of the following actions:

  • Nothing: stop execution.

    Nothing is executed
  • Whole script: execute the whole script.

    The whole script is executed
  • Everything below caret: execute everything below the caret.

    Everything below the caret is executed

For selection execute

If the code is selected (highlighted), perform one of the following options:

  • Exactly as one statement: execute exactly what is selected as a single statement.

    For example, consider this code snippet:

    BEGIN; UPDATE actor SET first_name='John' WHERE actor_id=100; UPDATE actor SET last_name='Doe' WHERE actor_id=100; COMMIT;

    Executing this code snippet as one statement will ensure that both UPDATE commands either succeed or fail together as part of the same transaction. If split into different statements, one could succeed while the other fails, disrupting the data integrity.

  • Exactly as separate statements: execute exactly what is selected. If the selection contains more than one statement, the statements are executed as separate statements.

    For example, if you want to run several SQL commands at once, and you don't necessarily need them all to succeed or fail together.

  • Smart expand to script: expand a selection to form a sequence of valid statements. For example, if there is at least one statement border within the selection, the selection is expanded to form a sequence of valid statements. This sequence is then executed. Otherwise, execute what is selected.

Open results in new tab

You can select to view query results on individual tabs, or on one and the same tab. For the single tab, the tab is updated for each query.

  • Select the checkbox to create a new tab with query results each time you run the SELECT query. Using this approach, you can keep results of all the queries that you have run.

  • If the checkbox is cleared, the same tab is used to show query results. Information on the tab is updated to show the result.

    In this case, when you get the result that you want to keep, you can pin the tab by right-clicking its header and selecting Pin Tab in the context menu.

Split a script for execution in Generic and ANSI SQL dialects

Set the query parsing for unsupported databases that use SQL:2016 or Generic dialects. The Generic dialect differs from SQL:2016 in error highlighting. In the Generic dialect, all found errors are not highlighted.

  • Into valid ANSI SQL statements or by separator: PyCharm analyzes a script and splits it on valid statements or by separators. This setting is default.

  • Into ANSI SQL statements: split scripts according to the SQL:2016 grammar.

  • By statement separator: extract and run statements by separators. For the Generic dialect, the separator is a semicolon.

Review parameters before execution

When you run a statement with parameters, PyCharm saves parameter values in memory. Select this checkbox and next time you execute the statement, PyCharm will show you the last used parameter values. You can change them before running the statement.

Clear this checkbox and PyCharm will execute the statement immediately without showing you the parameter values.

Show warning before running potentially unsafe queries

Select to display warnings for potentially unsafe queries.

If you forgot to put the WHERE or WHERE TRUE clause in DELETE and UPDATE statements, PyCharm displays a notification to remind you about that.

Notification when you type DELETE and UPDATE without WHERE

When you run the statements, PyCharm shows you the warning. If you omitted the WHERE or WHERE TRUE clause intentionally, you can execute current statements as you planned by clicking Execute in the warning.

Warning when you run DELETE and UPDATE without WHERE
Last modified: 14 October 2024