Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make PyCharm recognize placeholders in SQL statements?

Tags:

I'm using PyCharm and I have an error on this SQL statement:

SELECT * FROM table WHERE id= %(id)s

The code syntax inspection says:

<expression> expected, got '%'

Is there a way to disable this error message? In other words, how do I make PyCharm recognize placeholders in SQL statements?

Edit

Here is my solution:

For %(id)s and %s you have to had %\((\w+)\)s and %s in Settings/Preferences | Tools | Database | User parameters and select All languages not only SQL

like image 892
Julien Avatar asked Mar 18 '16 11:03

Julien


People also ask

Can you do SQL in PyCharm?

Database tools and SQLThe database management functionality in PyCharm is supported by the Database tools and SQL plugin.


1 Answers

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

like image 77
Nate Avatar answered Sep 29 '22 12:09

Nate