I try to execute essentially some sql like this (which gets builded in a complicated way):
sql = "SELECT COUNT(*) FROM entities WHERE (unit = '%')"
with this Python code:
engine.execute(sql)
What happens then is I get a
TypeError: 'dict' object does not support indexing
Why is this the case?
Not 100% sure, but I think SQLAlchemy is trying to intepret the
%character as a SQL parameter. I’d try doubling the%character to work around this:This depends on what database you are using; different database adapters use different parameter styles. The psycopg2 module, used for PostgreSQL database connections, for example uses the
%sstyle and documents that%%is the correct way to insert a%literal value into your SQL statements.