DataGrip 2022.2 Help

Query console

Overview

Query consoles are SQL files that are associated with a data source.

For example, if you open a query console for PostgreSQL, a connection session to the PostgreSQL data source is automatically created. When you open an SQL file from your hard drive, you need to specify the connection session first.

In the following example, the PostgreSQL console is attached to the production session. You can change the production session to testing or create a new session. Read more about managing sessions in Managing connection sessions.

Change the connection session

The input pane of a query console opens as a separate editor tab. The input pane is where you compose your SQL statements.

When you execute a statement, the Services tool window opens. The Services tool window displays available connection sessions, Output and Result tabs. For more information about the Services tool windows, see Services tool window.

If the executed statement retrieves data (for example, SELECT), results are displayed in the Result tab that has a title of a qualified table name. For more information about creating custom titles for result tabs, see Use custom titles for tabs with results.

Use custom titles for tabs with results

If the executed statement does not retrieve data, results are displayed in the Output tab.

Results in the Output tab

Before execution of a parametrized statement, you see the Parameters window where you can specify values for the parameters.

Run a statement with parameters

In order to run SQL scripts, treat the usages of the database objects as links, and provide you with correct code completion, DataGrip must resolve the database objects in your code to a certain context. By default, IDE uses one of the following as a starting point to resolve the database objects to: <schema> selector, or the default database (if none of the above is set).

For more information about resolve modes, refer to Resolve modes.

Code editor

Use the code editor to compose and execute your SQL statements as well as to perform other associated tasks.

Input pane of a query console

Toolbar icons and shortcuts

Item

Shortcut

Description

the Execute button Execute

Ctrl+Enter

Execute selected SQL statement or statements.

If nothing is selected, the current statement is executed.

Browse Data Source History Browse Query History

Ctrl+Alt+E

Open a dialog that shows all the statements that you have run for the corresponding data source.

See also, Using the History dialog.

View Parameters View Parameters

Open or close the Parameters dialog.

Settings Open Query Execution Settings…

Open the Database page of the Settings dialog to view or edit the settings for your database consoles, data editors, and the Database Explorer.

Tx:Auto Tx:Auto

Select the isolation level for database transactions and the way the transactions are committed.

  • Auto: each statement is executed in its own transaction that is implicitly committed.

  • Manual: transactions are committed or rolled back explicitly by means of Commit button or Rollback button on the toolbar.

Playground Playground

Select the resolve mode to manage the context that database objects in your code are resolved to.

  • Playground: default mode for query consoles. All the database objects are resolved to the same context.

  • Script: default mode for local SQL files. The USE SQL statement (SET search_path TO for PostgreSQL) overrides the default context that the database objects are resolved to.

For more information about the resolve modes, refer to Resolve modes.

Commit button Commit

Commit the current transaction.

Rollback button Rollback

Roll back the current transaction.

Cancel Query

Cancel Running Statements

Ctrl+F2

Terminate execution of the current statement or statements.

<schema>

Switch current schema

Select the default schema or database. For PostgreSQL and Redshift, use the <schema> list to form the schema search path.

Select a search path for PostgreSQL

Database session

Manage database connection sessions.

Productivity tips

Item

Shortcut

Description

Edit as Table

In INSERT statements, opens the editor for working with the data in a table format.

Edit data in INSERT statements as a table

For more information about using Edit as Table in INSERT statements, see Edit data in INSERT statements as a table.

Change Dialect (<CurrentDialect>)

Change the SQL dialect. Select a dialect from the list.

Explain Plan

Show an execution plan (or explain plan) for the current statement. The result is shown in a mixed tree/table format on a dedicated Plan tab.

Example of Explain Plan

Explain Plan (Raw)

Show an execution plan (or explain plan) for the current statement. The result is shown in table format. Technically, EXPLAIN <CURRENT_STATEMENT> or similar statement is executed.

Example of Explain Plan

Execute

Ctrl+Enter

Execute the current statement or the sequence of selected statements.

Execute to File

Execute the current statement and save results in a text file. Select the output format and specify the file location and name.

Run 'console [data_source]'

Ctrl+Shift+F10

Execute all the statements in the query console.

Output tab

Use the Output tab to view information about SQL statements and other operations that you performed in a query console. Also, the Output tab displays information about errors, timestamps, affected rows, query duration, the autocommit mode, and other operations.

The Output tab

Right toolbar

Item

Description

Soft-wrap

Wrap long lines of text.

Scroll to end

Scroll the output log to the end.

Print

Print a query console file, a selected text, or all the files in a directory.

Clear all

Clear the Output tab.

Context menu

Item

Description

Copy Copy

Copy the selected text.

Copy as Plain Text

Copy the selected text as plain text (without formatting).

Copy Reference

Copy a reference link to a file or a line.

Compare with clipboard Compare with clipboard

Open the Clipboard vs Editor dialog where you can see the diff between the selected text and the text that you copied to a clipboard.

Search with Google

Open a browser and run a search on Google for the selected text.

Fold Lines Like This

Fold the lines that include the selected text.

Pause Output

Pause the output logging.

Clear All

Clear the output log.

Result tab

Use the Result tab to see the data that was retrieved from the database in a table format. You can sort, add, edit, and remove data as well as perform other associated table tasks. For more information about working with tables, rows, columns, and cells, see Tables.

Result tab in the Services tool window

Main functions

Most of the functions in the Result pane are accessed by using controls on the toolbar, context menu commands for the data cells, and associated keyboard shortcuts. You can see what other actions with tables you can perform in Tables.

Most of

Item

Shortcut

Description

First page, Previous page, Next page, Last page

Use navigation icons and corresponding commands for switching between pages that show the retrieved data.

A number of rows that you see on the Result tab are referred to as a result set page. If this number is less than the number of rows that satisfy the query, only a subset of all the rows is shown at a time. If all the rows are currently shown, navigation icons and the corresponding commands are inactive. You can see the limit between the navigation buttons. You can change it here by clicking and selecting the necessary limit or in settings.

  • First page: jump to the first page of results.

  • Previous page: go to the previous page of results.

  • Next page: go to the next page of results.

  • Last page: jump to the last page of results.

To change the size of a result set page, open settings (Ctrl+Alt+S) and navigate to Database | Data Editor and Viewer. In the Limit page size to field, type a new size of a result set page. Alternatively, to disable the page size restriction, clear the Limit page size to checkbox.

Reload page

Reload Page

Ctrl+F5

Reload data for the table view to synchronize the data that you see in the editor with the contents of the database. Also, use the Reload Page button when you want to apply a new page size limit setting after its change.

Add Row

Add Row

Alt+Insert

Add a row to the table.

To save a new row, click Submit the Submit button.

The Add Row button is disabled in the inappropriate context. For example, if the current table does not permit adding rows.

For more information about working with rows, see Rows.

Delete Row

Delete Row %s

Ctrl+Y

Delete the selected row or rows.

To select multiple rows, click numbers in the gutter. Also, you can press Ctrl and click the necessary rows.

The Delete Row button is disabled in the inappropriate context. For example, if the current table does not permit removing rows.

Tx isolation Transaction mode

Select the isolation level for database transactions and the way the transactions are committed.

  • Auto: the current transaction is committed automatically.

  • Manual: the changes submitted to the database server are accumulated in a transaction that can either be committed or rolled back.

the Submit button Submit

Ctrl+Enter

Submit local changes to the database server. For more information about submitting and reverting changes, see Submit changes to a database.

Commit Commit

Commit the current transaction. Also, you can see information about transaction modes.

Rollback Rollback

Roll back the current transaction. Also, you can see information about transaction modes.

Cancel Query

Cancel Running Statements

Ctrl+F2

Terminate execution of the current statement or statements.

Compare with

Compare Data

Compare the current table with the table in the Services tool window. For more information about comparing tables, see Compare table data.

Pin button Pin Tab

Pin the tab to the tool window to keep the query result.

For more information about pinning tabs, see Pin the tab with query results.

Data Extractor

Data Extractors

Select an output format for your data.

Also, you can configure the following options:

  • Skip Computed Columns (SQL): do not include virtual columns that are not physically stored in the table (for example, the identity column).

  • Skip Generated Columns (SQL): for INSERT and UPDATE statements, do not include auto-increment fields when copying or saving data.

  • Add Table Definition (SQL): for INSERT and UPDATE statements, add the table definition when copying or saving data.

  • Configure CSV Formats: open the CSV Formats dialog where you can manage your delimiter-separated values formats (for example, CSV, TSV).

  • Go To Scripts Directory: open a directory with scripts that convert table data into different output formats.

Data extractors

Export Data

Export Data

Export the table data to the clipboard or save to a file.

Export to Database Export to Database

Export the data to another table, schema, or database. In the Choose Target dialog, select the target schema (a new table is created) or table (the data is added to the selected table). In the Import Table dialog, customize mappings.

Show Options Menu

Show Options Menu

The Show Options Menu list includes the following options:

  • Show Geo Viewer: enable a graphic viewer to explore geospatial data in your database.

  • Reset View: restore the initial table view if you customized the table view before (for example, hidden columns or sorted data).

  • Paste Format: select how you want to treat the text from the clipboard on paste.

  • View Query: view the query that generated the table.

  • Open Query Execution Settings…: open the Database section in settings. In the Database section, you can view or edit the settings for your database consoles, data editors, and the Database Explorer.

View

F2

View a value in the selected cell or cells. The View command is available for read-only values. If the cell is editable, you see the Edit command.

Edit

F2

Edit a value in the selected cell or cells. Alternatively, you can double-click the cell and start typing a value. The Edit command is unavailable for read-only values.

  • To open the auto-completion list, press Ctrl+Space.

  • To enter the modified value, press Enter.

  • To cancel editing, press Escape.

For more information about editing cells, see Cells.

View Maximized

F2

Expand the selected cell to view a value in the cell.

Maximize

F2

Expand the selected cell to edit a value in the cell.

In a maximized cell, press Enter to start a new line. To enter the value, press Ctrl+Enter. To restore an initial value and quit the editing mode, press Escape.

For more information about editing cells, see Cells.

Set DEFAULT

Ctrl+Alt+D

Set the default value or values that you specified for the column. To view the default column value, right-click a table in the Database Explorer (View | Tool Windows | Database Explorer) and select Modify Table. Double-click the column entry and see the value in the Default field.

Set NULL

Ctrl+Alt+N

Replace the value or values with NULL. To ensure that the column accepts NULL values, right-click a table in the Database Explorer (View | Tool Windows | Database Explorer) and select Modify Table. Double-click the column entry and see if the Not null checkbox is cleared.

Load File…

Load a file into the field.

Revert

Ctrl+Z

Revert changes within the selection. For more information about reverting changes, see Submit changes to a database.

Clone Row

Ctrl+D

Create a copy of the selected row.

Quick Documentation

Ctrl+Q

Open the quick documentation view. To close the view, press Escape. For more information about quick documentation, see Using the quick documentation view.

View as | Transpose

Toggle the transposed table view. In the transposed view, the rows and columns are interchanged.

To make this mode a default for tables and views, open settings by pressing Ctrl+Alt+S and navigate to Database | Data Views and select the Automatically transpose tables. When this option is enabled, query results are not transposed.

Go To | Row…

Ctrl+G

Jump to a specified row. In the Go to Row dialog, specify the column and row number (use the column:row pattern).

Go To | All Related Rows

F4

Jump to a related record. The command options are a combination of those for Go To | Referenced Rows and Go To | Referencing Rows. Read more about related data in Navigate between related data.

The command is not available if there are no related records.

Go To | Referenced Rows

Ctrl+B

Switch to a record that the current record references. If more than one record is referenced, select the target record in the popup that appears. Read more about related data in Navigate between related data.

The command is not available if there are no referenced records.

Go To | Referencing Rows

Alt+F7

Use this command or shortcut to see the records that reference the current record. Read more about related data in Navigate between related data. In the popup that appears there are two categories for the target records:

  • First Referencing Row: all the rows in the corresponding table are shown, and the first of the rows that references the current row is selected.

  • Referencing Rows Only: only the rows that reference the current row are shown.

The command is not available if there are no records that reference the current one.

Copy

Ctrl+C

Copy the selection to the clipboard.

Paste

Ctrl+V

Paste the contents of the clipboard into the table.

Save LOB…

Save a binary large object (LOB) currently selected in the table in a file.

Last modified: 08 August 2022