0

I'm using a simple Python function to run a SQL file (still using Python 2.7).

Relevant parts of the function used:

sql_query = read_file(file_path)
engine = sqlalchemy.create_engine(connection)
engine.execute(sql_query)

When running, I get this error

TypeError: 'dict' object does not support indexing

After looking it up I found this : TypeError: 'dict' object does not support indexing thrown on second instance of this query

and in the SQL query, I am using a condition of LIKE '%abc%'. Is there any way to solve this without having to change my SQL query?

Thanks

0

1 Answer 1

2

Use Textual SQL to tell SQLAlchemy to treat the string as raw SQL.

from sqlalchemy.sql import text

sql_query = read_file(file_path)
engine = sqlalchemy.create_engine(connection)
engine.execute(text(sql_query))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.