SQL code inspection complains on unresolved table names in SQL queries (PostgreSQL)
已回答
All my SQL queries are marked bloody-red because IDE cannot resolve names of tables. I think the problem is that I assume specific search_path is set before executing the queries. I selected my schema in the connection for introspection, also "Switch Schema" is set to "Automatic" in the connection options. Additionally I chose my schema in the drop-down list located in the line below my .py tab. When the query is put into a Database Console with the same settings it does not show any problems, table names are resolved correctly.
Is there anything else to try to make it work? Thank you.
My PyCharm version is Pro 2019.3.
请先登录再写评论。
Hello,
The thing is that the search path should be configured properly for every SQL user (or set by default).
Antonina Belianskaya sorry, cannot accept this method as a solution. We usually do not configure search paths for SQL users (and you cannot always assume that a developer has control over the database to do that). This feature, while being available in Postgres, is by no means recommended, nor a good practise. Usually it is used when a program assumes that objects are in 'public' schema and has no options to change the default schema. In other words, it is a workaround invented by Postgres developers for poor client programs.
Another consideration here is that the behaviour of JetBrains products is expected to be consistent. I can chose the search path in DataGrip. Also as I mentioned in my question, if I put the query in the Database Console of PyCharm, it does not indicate any problems (because I checked boxes for schemas of my interest). Why do you think the behaviour of SQL code inspection must be different?
Hello,
You can configure 'search path' for different files and folders: press 'Shift' button twice, type 'SQL resolution', click 'SQL Resolution Scopes' and here you can set entire project mapping to some database/schemas or map any folder to any schema(s).
This works great! Thank you.
I wish though, it would be more intuitively accessible from the editor, e.g. through 'light-bulb' context menu.