DataGrip 2022.1 Help

Query consoles

Query or database consoles are SQL files in which you can compose and execute SQL statements. Unlike scratch files, consoles are attached to a data source. You can use a query console in the same way as you use a terminal. Just type and run your code.

When you create a data source, a query console is created automatically. If necessary, you can create additional consoles. Each console creates a new connection. If you do not want to create new connections, enable single session mode.

All the created query consoles are in the internal Database Consoles directory. To open this folder, open the Files tool window (Alt+2) and navigate to Scratches and Consoles | Database Consoles.

The following video gives a short overview of query consoles in DataGrip.

Working with console files

Create a query console

To create a console, use one of the following actions in the Database Explorer (View | Tool Windows | Database Explorer).

  • Click a data source and select File | New | Query Console.

  • Right-click a data source and select New | Query Console.

  • Click a data source, press Alt+Insert, and select Query Console.

  • Click a data source, press Ctrl+Shift+F10, and select New Query Console.

Open a console

When a console is open, you can write SQL here, run it and get the result.

  • In the Files tool window (View | Tool Windows | Files), navigate to Scratches and Consoles | Database Consoles | <data_source_name>, double-click a console file.

  • In the Database tool window, click the Jump to Query Console… icon (the Jump to console icon ) and select a console that you want to open or create a new one.

  • Click a data source, press F4, and select the console that you need.

    Open a console

Rename a query console

  1. In the Files tool window (View | Tool Windows | Files), navigate to Scratches and Consoles | Database Consoles.

  2. Expand a data source group that includes your console.

  3. Right-click a console file and select Refactor | Rename.

Group consoles under the data source directory

  1. In the Files tool window (View | Tool Windows | Files), navigate to Scratches and Consoles | Database Consoles.

  2. Right-click a data source group where you want to create a new directory, select New | Directory.

  3. Specify a name of the directory.

  4. Select and drag console files to the directory.

  5. In the Move dialog, click OK.

    Group consoles under the data source directory

Delete a query console

  1. In the Files tool window (View | Tool Windows | Files), navigate to Scratches and Consoles | Database Consoles.

  2. Expand a data source group that includes your console.

  3. Right-click a console file and select Delete.

Copy a console file to a new location

  1. In the Files tool window (View | Tool Windows | Files), navigate to Scratches and Consoles | Database Consoles.

  2. Expand a data source group that includes your console.

  3. Right-click a console file and select Refactor | Copy File….

  4. In the To directory field, specify a new location for the file.

    Copy a console file to a new location

Save a console as a file

  • In the console file, press Ctrl+Shift+S. Navigate to the directory where you want to store the file.

    Save the console contents as a file

Configuring console settings

Modify console settings

  1. Open a console and click the Data Source Properties icon (the Open Database Settings icon).

  2. Open settings by pressing Ctrl+Alt+S, navigate to Database | Query Execution. For more information about the settings, see Query execution.

    Modify console settings

Configuring console dialects

Change the SQL dialect in the editor

  • Right-click the editing area of the input pane and select Change Dialect (<current_dialect>). In the Change SQL Dialect window, select a dialect.

    Note that the selected dialect is applied to all the data sources that were created with the current driver. For example, let's say that you have several data sources that use the PostgreSQL driver. If you change the dialect to Greenplum in one console, all the consoles and data sources that use the PostgreSQL driver will switch to the Greenplum dialect.

    Change the SQL dialect in the editor

Disable syntax error highlighting

  • Right-click the editing area of the input pane, select Change Dialect, and select Generic SQL. The Generic SQL dialect supports completion and highlighting for SQL keywords, table and column names. Syntax error highlighting is disabled, that is all statements in a query console are shown as syntactically correct).

Productivity tips

View history of a query console

  • In a console, right-click any area and select Local History | Show History.

Apply a code style in the editor

  • Right-click any area in the editor and select Reformat. Alternatively, press Ctrl+Alt+L.

    Apply a code style in the editor

View the file path of a query console

  • To see the details of a file, hover the cursor over the console tab.

    View the file path of a query console
  • Press Alt+F1, select Files View and press Enter.

    Navigate to a console file from the Select In window

Rename a console file

  • Right-click a console tab, and select Rename File.

  • Open the Files tool window (View | Tool Windows | Files) and navigate to Scratches and Consoles | Database Consoles. Select the console file, and press Shift+F6.

    Rename a query console file
Last modified: 14 July 2022