"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

1
14 comments

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

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

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

0

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

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

Maybe someone could help me on this thread. I too get the "Unable to resolve column" inspection error in DB console on PyCharm 2021.1.1. I am using Snowflake. I have made sure that the necessary schemas are selected and I can see them in the inspector. The column name is plainly visible in the inspector. Not sure what I am doing wrong, or if this is simply a bug:

0
Avatar
Yuriy Vinogradov

@... you need to properly configure File | Settings | Languages & Frameworks | SQL Dialects  & File | Settings | Languages & Frameworks | SQL Resolution Scopes  for project(or file), then they will be resolved.

0

Thank you @... for replying. Do you see anything I should be doing differently?

Note that the partially obscured Path is to the root of my Python project in both cases, and the proper databases and schemas are selected for Resolution Scope.

I'm open to any other suggestions. I am finding it ever so frustrating that I haven't been able to solve this.

0
Avatar
Yuriy Vinogradov

the issue is that you have {table} parameter in query, and it does not work properly. I mean, even if this variable is declared somewhere above, it just won't be recognized in SQL injection.

2

@..., that was indeed the issue. Thanks!

0

@Yuriy Vinogradov is there any way to solve this issue keeping the table name inside a variable? Thanks!

0

Martini Giulia94, if you have the same problem and SQL is injected into some files, then there is no way to keep the table name inside a variable.

0

Please sign in to leave a comment.