Working with 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 located in the internal Database Consoles directory. To open this folder, open the Files tool window (Alt+2) and navigate to . On your machine, the query console files are stored in the consoles subdirectory of the IDE configuration directory.
The following video gives a short overview of query consoles in DataGrip.
For information about working with query results in query consoles, refer to Query results.
Working with console files
Create a query console
To create a console, use one of the following actions in the Database Explorer ( ).
Click a data source and select
.Right-click a data source and select
.Click a data source, press Alt+Insert, and select Query Console.
Click a data source, press Control+Shift+F10, and select New Query Console.
Click a data source and press Control+Shift+Q.
Open a console
When a console is open, you can write SQL here, run it and get the result.
In the Files tool window ( ), navigate to , double-click a console file.
In the Database Explorer, click the Jump to Query 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.
Rename a query console
To rename a query console file, do one of the following:
Right-click a console tab, and select Rename File.
Open the Files tool window ( ) and navigate to . Expand a data source group that includes your console, right-click the console file, and select (Shift+F6).
Group consoles under the data source directory
In the Files tool window ( ), navigate to .
Right-click a data source group where you want to create a new directory, select
.Specify a name of the directory.
Select and drag console files to the directory.
In the Move dialog, click OK.
Delete a query console
In the Files tool window ( ), navigate to .
Expand a data source group that includes your console.
Right-click a console file and select Delete.
Copy a console file to a new location
In the Files tool window ( ), navigate to .
Expand a data source group that includes your console.
Right-click a console file and select
.In the To directory field, specify a new location for the file.
Save a console as a file
In the console file, press Control+Shift+S. Navigate to the directory where you want to store the file.
Open a console file in the file browser
To open a console file in your file browser, do one of the following:
Right-click a console tab and navigate to
.Open the Files tool window ( ) and navigate to . Expand a data source group that includes your console, right-click the console file, and select .
Configuring console settings
Modify console settings
Open a console and click the Data Source Properties icon ().
Open settings by pressing Control+Alt+S, navigate to Query execution.
. For more information about the settings, see
Configuring console dialects
Change the SQL dialect in the code editor
Right-click the editing area and select Change Dialect (<current_dialect>) to. In the Change SQL Dialect window, select a dialect.
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
.
Apply a code style in the editor
Right-click any area or a selection of code in the editor and select Reformat. Alternatively, press Control+Alt+L.
View the file path of a query console
To see the details of a file, hover the cursor over the console tab.
Navigate to a console file from the Select In window
Press Alt+F1, select Files View and press Enter.