DataGrip tips and tricks (part 2)
3 min read

DataGrip tips and tricks (part 2)

DataGrip tips and tricks (part 2)

You can read part 1 here!

Multiple cursors

You can edit multiple lines by pressing Ctrl twice, holding it, and placing new cursors with the arrow keys. Another option is enabling the Column Selection Mode (Edit Column Selection Mode).

I usually use these options to create a Common Table Expression (CTE) with temporary data to check. This way, I avoid going through creating a temporary table in the database.

Another way to use multiple cursors is through text search (Ctrl+F) + Select All Occurrences (Alt+F3). This option allows you to edit every result throughout the entire query in one go.

Compare files and Compare results

One of my favorite features of DataGrip is that I don't need to use other applications for many frequent data-related tasks. For example, from the same DataGrip, you can compare SQL files (or any other text file) or the results of a query.

For that, you can use the Compare with option (you can access it quickly with the Find any action option, Ctrl+Shift+A).

To compare results from the Service tool window and the active data grid, you can click on the icon with the two opposite arrows and select the other data grid you would like to compare.

In both cases, DataGrip will highlight the differences even better than other diff tools.

DataGrip - Compare results

New file from selection

If you have the editor full of queries and want to start from scratch with only one of them, you can select it, press Ctrl+N, and have a new clean scratch file with only that query.

DataGrip - New file from selection

Find in files

Sometimes you need to retrieve a query made a few weeks before or some lost SQL file. You may also need to check if a specific table is being used in a package of your data source. In those cases, the Find in files option (Ctrl+Shift+F6) comes in handy.

Additionally, you can restrict the search scope to search only, for example, among Recently viewed files, Attached directories, Open files, Data sources, or a specific folder.

Virtual foreign keys

If a relationship between two tables exists but is not defined in the database, you can save a virtual relationship or create a custom rule to guess the relation. This way, DataGrip will show the completion when writing the join clause, and it will show the relationship in the diagrams.

To save a virtual relationship, just press Alt+Enter, and select Store table relation.

To create a custom rule, go to Settings  Editor General Code completion Suggest non-strict foreign keys based on the name matching.

You can find more info here.

Bonus: Copy string concatenation text to SQL

This is not really a feature of DataGrip, but of IntelliJ. If you work with both applications, you may not know that you can copy the SQL of a concatenated text string from your code in IntelliJ and paste it into DataGrip in its original version without quotation marks and plus symbols.

To achieve this, press Alt+Enter and select Copy string concatenation text to the clipboard.

On the other way, from DataGrip to IntelliJ, you can paste your SQL query into IntelliJ, inside the string quotes, and it will be concatenated automatically.