"Unable to resolve column" inspection error in DB console

Answered

I'm using DB2 in the IntelliJ DB console and SQL files and I get red highlighting across all my column names.

I had a look at https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003671819--Unable-to-resolve-column-inspection-error-in-DB-console but nobody picked up on my post perhaps because that is PhpStorm. So I came over here.

I've followed your instructions to set up the SQL Resolution Scopes in my settings, but that doesn't let me add any mappings except for the whole project.

 

This is a maven project with nested modules, which I am suspicious of - is that relevant?

Thanks

Adam

7 comments
Comment actions Permalink

Database console does not need path mappings - it is automatically uses the it's own data source configuration for searching the schema. 

Make sure you have selected the default schema for the sql console: https://www.jetbrains.com/help/datagrip/schemas.html#selecting_schema

If issue remains, attach screenshots describing the problem.

1
Comment actions Permalink

OK, here you go. You can see the red highlighting for all the "not found" errors - table names and columns - and you can see the schema is selected:

0
Comment actions Permalink

Schema is selected but there are no db objects. Please follow steps 2 and 3 from https://www.jetbrains.com/help/datagrip/cannot-find-a-database-object-in-the-database-tree-view.html

2
Comment actions Permalink

OK cool! That sorted it out. DB2 is obviously a different beast from mysql, mariadb, sql server or oracle.

0
Comment actions Permalink

I have a similar issue when using a MySQL/MariaDB. I have a generic PHP script that uses either a SELF::CONSTANT_DB_NAME or SELF::CONSTANT_TABLE_NAME or a $variable_db_name or $variable_table_name when building the required queries. The PHP script loops over and array of SQL statements. 

"PostSQL" => array(
"INSERT into $dbTo.GroupInfo (pl.pgNum, pl.plPUNum) SELECT '3', 'pl.plPUNum' FROM $dbTo.ProductList pl " .
"WHERE pl.plPUNum REGEXP 'YourNameHere';",
)

In this snippet, it complains that 'Unable to resolve pl' if the 'pl' is removed then it cannot resolve the column names:

"PostSQL" => array(
"INSERT into $dbTo.GroupInfo (pgNum, plPUNum) SELECT '3', 'pl.plPUNum' FROM $dbTo.ProductList " .
"WHERE plPUNum REGEXP 'YourNameHere';",
)

These statements work as expected, but PHPstorm can't resolve the columns. If the table name is directly specified, then it works as expected.

1
Comment actions Permalink

I have the scopes correctly set as.  The issue is that PHPStorm does not seem to parse the table name as a variable.

$dbTo.tableName and associated column names are not correctly identified.

If in the above example is the variable $dbTo replace with the correct table name then all is good:

"PostSQL" => array(
"INSERT into MyDbName.GroupInfo (pgNum, plPUNum) SELECT '3', 'pl.plPUNum' FROM MyDbName.ProductList " .
"WHERE plPUNum REGEXP 'YourNameHere';",
)

 

0

Please sign in to leave a comment.