How do I make PyCharm recognize placeholders in SQL statements?

不羁岁月 提交于 2019-12-03 01:31:31

Is this SQL in a SQL console, or in a string in a Python script? I had this same issue and solved it by checking the box above the list of patterns, labeled "Enable in string literals with SQL injection". If you're doing this in a SQL console window, check the first box.

As @LazyOne notes, go to Settings/Preferences > Tools > Database > User Parameters and you'll see two checkboxes at the top:
Enable in console and SQL files
Enable in string literals with SQL injection

While you can add your own custom patters, I believe the pattern that matches this parameter syntax (for me, parameters for psycopg2 for use in Postgres) is out-of-the-box in Pycharm, the last one in the list.

See here for reference:
https://www.jetbrains.com/help/pycharm/2016.1/user-parameters.html

In addition to @Nate's answer (built-in regex %\((\w+)\)s works for PostgreSQL), i've managed to get this work only via reordering the patterns and moving target regex to the top of the list.

One could also try to disable other rules and see if that helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!