IntelliJ IDEA 2019.2 Help

Query results

Usually, when you run a query, you receive results in a table format. Each statement appears in a separate tab in the Services tool window. For example, if you have two SELECT statements in the query, you will see two tabs in the tool window.

The Services tool window includes a list of consoles that are grouped according to a connection session to a data source.

Open a new tab for each query

By default, IntelliJ IDEA updates the same tab with results each time you run a query. You can change this behavior and create a tab each time you run a query.

  1. In the IDE settings Ctrl+Alt+S, go to Tools | Database | General.

  2. Select the Open results in new tab checkbox and click OK.

Use custom titles for tabs with results

You can define a tab title in the comment section before the query. In the Treat text as title after field, you can reserve a combination of symbols or characters, and any text after this combination will be treated as a tab title. By default, no combination is used, so any text after -- or /* is treated as a tab title.

To disable this feature, open settings Ctrl+Alt+S, navigate to Tools | Database | General, and clear the Create title for results from comment before query checkbox.

  1. In settings Ctrl+Alt+S, navigate to Tools | Database | General.

  2. In the Treat text as title after field, define a combination for tab titles.

Use custom titles for tabs with results

Edit values in the result set

  1. In the result set, click a cell value that you want to edit.

  2. Specify a new value and press Enter.

  3. To submit changes to a database, click the Submit icon (The Submit icon), or press Ctrl+Enter.

Modify values in the result set

Export to a file

  • Right-click a %result_set%, select Dump Data | To File.

  • Right-click a query, click Execute to File and select the file type that you want to use for export (for example, Comma-separated (CSV)).

  • On the toolbar, click the Dump Data icon (The Dump Data icon) and select To File.

Export a view to a file

Export to a clipboard

  • Select data in the result set or in the editor and press Ctrl+C.

  • On the toolbar, click the Dump Data icon (The Dump Data icon) and select To Clipboard.

Export a view to the clipboard

Compare two result sets

  1. Run queries to tables that you want to compare.

  2. In the Services tool window, click the Compare with icon (The Compare with icon), and select the result set that you want to add to diff.

  3. If needed, change a value of the Tolerance parameter in the comparison dialog. The Tolerance parameter defines a maximum number of differences that are allowed between two result sets. For example, if you want to consider two rows as equal if their data differs in a single column, enter 1 in the Tolerance field.

You can retrieve rows from the table for the selected object, and move the focus to the object. For example, select a field in the project tree and press Ctrl+Alt+B. The focus moves to the corresponding column in the new tab.

To navigate to the object in the result set, select an object and go to Navigate | Related Symbol Ctrl+Alt+B.

Navigate between related data

You can navigate between different types of related data:

  • Referenced data: data that is referenced by the current object.

  • Referencing data: data that is referencing the current object.

Referenced and referencing data
  1. Right-click the column in the table and navigate to Go To | Referenced Data Ctrl+B or Go To | Referencing Data Ctrl+Alt+B.

  2. If the Choose target popup appears, select the table and what rows to show:

    • First Referencing Row: all rows in the table. The first row that references the current row is selected.

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

  3. Press Enter

Pin the tab with query results

If one and the same tab is used to show your query results, and you get the result that you want to keep, you can pin the tab to the tool window.

  • Right-click the tab and select Pin Active Tab.

  • Click Pin button on the toolbar.

Pin the result tab

Sort data

To sort table data in a column, click the cell in the header row.

State

Description

No sorting

Indicates that the data is not sorted in this column. The initial state of the sorting marker.

Ascending order

The data is sorted in the ascending order. The number to the right of the marker (1 on the picture) is the sorting level. You can sort by more than one column. In such cases, different columns will have different sorting levels.

Descending order

The data is sorted in the descending order.

Reset the initial table view

Click the settings icon (the settings icon) and select Reset View. As a result, the data becomes unsorted, the columns appear in the order they were defined initially, and all the columns are shown.

Operations with columns in the structure view

The structure view displays you a list of all the columns in the selected table. The structure view is available in the Structure tool window (View | Tool Windows | Structure) or in the popup window (Ctrl+F12).

You can perform the following operations with columns:

  • Sort the data in the ascending Shift+Alt+Up or the descending order (Shift+Alt+Down).

  • Reset the state of sorting (Ctrl+Shift+Alt+Backspace )

  • Hide a column or show a hidden column (Space). The names of hidden columns are shown struck-through.

    Operations with columns in the structure view

Export data to a database

  1. Make sure that the database is added as a data source in the Database tool window.

  2. Right-click any cell in the table and then click Export to Database.

  3. Specify the database, target schema (to create a new table with the exported data) or table (to add exported data to an existing table).

  4. Configure the data mapping and settings for the target table.

Logging SQL activity

Change location of the SQL log

To change location of the SQL log, add the -Didea.system.path property to the custom VM options. This change affects all logs.

  1. Click Help | Custom VM options.

  2. At the end of the option list, add the following line: -Didea.system.path=/path/to/your_log_directory.

Change location of the SQL log
Last modified: 17 October 2019