DataGrip
 
Get DataGrip

SQL Resolution Scopes

Last modified: 11 October 2024

By using SQL resolution scopes, you can associate a folder or a file with a specific data source. When you set this mapping, you can use coding assistance that corresponds to the associated data source.

When SQL resolution scopes are set, the IDE suggests database objects that are suitable for the associated data source. Consider that you have two data sources, one for your production database (PostgreSQL 14) and the other one for your test database (PostgreSQL 12.8). Tables in both databases have the same names, but databases have different structures. You can associate SQL files with either database separately.

Let's map postgresql_12.sql to the PostgreSQL 12.8 data source and postgresql_14.sql to PostgreSQL 14.

SQL Resolution Scopes

Both data sources have the actor table, but this table is stored in different schemas (guest.public.actor and postgres.public.actor). So, if we try to qualify the actor table or use code completion, completion suggestions will be associated with a corresponding data source.

Suggestions in the completion list

And, if we exchange queries between these files, we will get errors (lines 14-15). Because we do not have tables under guest.public in PostgreSQL 14, and there is no postgres schema in PostgreSQL 12.8.