- changed status to invalid
Bad parameter conversion on execute when it is list with one element
Issue #3018
invalid
some_list = [1, ] # list with one element
query = "SELECT * FROM some_table WHERE id IN :param_list "
params = { "param_list": some_list }
result = db_session.execute(expression.text(query), params)
query will look like:
SELECT * FROM some_table WHERE id IN ('1',)
When we want to pass list as a parameter to query, and the list has one element there is added coma at the end that breaks the query. When list has more elements there is no additional coma at the end so the query is fine.
Tested on 0.7.4. Didn't check newer versions.
Comments (3)
-
repo owner -
reporter Thanks for clarification.
-
repo owner - removed milestone
Removing milestone: 0.7.xx (automated comment)
- Log in to comment
the format of a SQL IN clause is:
your string is missing parenthesis and also is making the mistake that it assumes a list will be expanded somehow to modify the text of the SQL. No such capability exists. For auto-expansion of a list into individual components within IN, use the core expression language, see below:
we do seem to be short on documentation for in_() however, that should be fixed.