SQL Resolution Scopes
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
Both data sources have the
actor table, but this table is stored in different schemas (
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.
And, if we exchange queries between these files, we will get errors (lines 14-15). Because we do not have tables under
PostgreSQL 14, and there is no
postgres schema in
Add an SQL resolution scope
Press Control+Alt+S to open the IDE settings and then select.
Click the Add button.
In a file browser, navigate to a file or a directory that you want to associate with a data source.
Click the cell of the Resolution Scope column and select a data source that you want to associate with this directory or file.
To use SQL coding assistance in your project code, enable language injections.
A set of data sources, databases, and schemas used by default by all the SQL files in your project to resolve unqualified names of database objects.
If no mappings are set in the table below, files and directories use the project mapping.
Path to a file or a directory that you want to associate with a data source or a set of data sources.
A data source or a set of data sources that will be associated with a file or a directory.
If you add a mapping for a directory with files that are already associated with a data source, the IDE displays a notification dialog. In this dialog, you must select whether children should inherit the parent's scope or preserve their scope.