orator
orator copied to clipboard
list index out of range error in query connection
When I execute a sql query in orator, it throw out folling error
Traceback (most recent call last):
File "C:\Anaconda3\lib\site-packages\orator\connections\connection.py", line 32, in _run
result = wrapped(self, query, bindings, *args, **kwargs)
File "C:\Anaconda3\lib\site-packages\orator\connections\connection.py", line 209, in select
cursor.execute(query, bindings)
File "C:\Anaconda3\lib\site-packages\psycopg2\extras.py", line 142, in execute
return super(DictCursor, self).execute(query, vars)
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/cjf/PycharmProjects/AnacondaTest/fetch_controllerxy_from_memxy.py", line 49, in <module>
'''.format(p[0], p[1], p[2])
File "C:\Anaconda3\lib\site-packages\orator\connections\connection.py", line 35, in _run
e, query, bindings, wrapped
File "C:\Anaconda3\lib\site-packages\orator\connections\connection.py", line 357, in _try_again_if_caused_by_lost_connection
raise QueryException(query, bindings, e)
orator.exceptions.query.QueryException: list index out of range
I have found the reason. In my sql, there is a
WHERE e.wafername LIKE '{}%'
where '%' cause the problem.
So how to solve it?
The Percent sign needs to be part of the string you are using with parameterized queries.
For Example
query = "%" + "Bob" + "%"
sql_query.where_raw("CONCAT(title,summary) LIKE %s", query)
I hope this helps, but you didn't give me much information to go off of so 😅