DataGrip Overview, Part 4: Running Queries
In a Nutshell
DataGrip runs queries based on cursor position without needing explicit selection, with a customizable popup for choosing current query, entire script, or smallest query. Results appear in the Services tool window with tabs that can be named via preceding comments, and you can view explain plans in tree or graph mode. Query duration shows in tooltips, and results can display inline below each query within the editor.
These notes were generated by AI and may contain inaccuracies.
When running queries in DataGrip, you don't need to specify the code because DataGrip understands where your typing pointer is. If the file contains multiple queries, DataGrip will present you with a selection tool so that you can run the current query or the entire script. This means you don't need to specify the queries to run them, although that method also works. Note that subqueries and common table expressions are also available as run options, making it easier to debug queries with these structures.
This behavior is customizable. To go to settings, click on "Customize" at the bottom of the selection tool. Here, you can specify whether the selection tool will actually appear and assign three different shortcuts for three different behaviors. One of the most useful of these behaviors is running the smallest query that is under the writing cursor. You won't even need to choose anything.
The results are placed in the services tool window. On the left side of this window, there is a list of connections, each with its own node. You can adjust the services window layout by moving services to their own separate tool windows. Right-click on the service and select "open a new tab".
You can use the Output tab in the Services window to view information about SQL statements and other operations you performed on the query file. Also, the Output tab displays information about errors, timestamps, affected rows, query duration, autosave mode, and other operations.
The Results tab in the Services window displays the data retrieved from the database in a table format. You can sort, add, edit, and remove data, as well as perform other table-related tasks.
To view the statement implementation plan, click the "explain plan" button in the toolbar. By default, the plan is displayed in tree mode, but you can also switch to graph mode if you prefer. The thickness of the arrow indicates whether the cost of the operation is high.
In addition, you can give names to the results tabs. Just write a comment before each query. For example, I have the comment here, "Tab number one", and near the second query, "Tab number two". After running, you will see that the two tabs now hold the names of the comments that came before the queries.
After running the query, you can see how long it took for your query to run. The result is displayed in the tooltip on the success icon next to the query. Also, while running a long query, you can find the Cancel button in the same area.
Another way to clearly see the relationships between queries and results is to use the results mode within the editor. Switch the results button inside the editor located in the toolbar, and the results will appear directly below each corresponding query, within your query file.
Keep JetBrains in your library
Save the videos and channels worth coming back to, and find them again in one place.





