pypipostgresql95% confidence\u2191 208

Strange SQLAlchemy error message: TypeError: 'dict' object does not support indexing

Full error message
I am using hand crafted SQL to fetch data from a PG database, using SqlAlchemy. I am trying a query which contains the SQL like operator '%' and that seems to throw SqlAlcjhemy through a loop:

sql = """
       SELECT DISTINCT u.name from user u
        INNER JOIN city c ON u.city_id = c.id
        WHERE c.designation=upper('fantasy') 
        AND c.id IN (select id from ref_geog where short_name LIKE '%opt')
      """

# The last line in the above statement throws the error mentioned in the title. 
# However if the last line is change to:
# AND c.id IN (select id from ref_geog where short_name = 'helloopt')
# the script runs correctly.
#
# I also tried double escaping the '%' i.e. using '%%' instead - that generated the same error as previously.

connectDb()
res = executeSql(sql)
print res
closeDbConnection()

Any one knows what is causing this misleading error message and how I may fix it?

[[Edit]]

Before any one asks, there is nothing special or fancy about the functions included above. For example the function executeSql() simply invokes conn.execute(sql) and returns the results. The variable conn is simply the previously established connection to the database.

You have to give %% to use it as % because % in python is use as string formatting so when you write single % its assume that you are going to replace some value with this. So when you want to place single % in string with query allways place double %.

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/361d8ac7fc72e97f796b82fcbc255d44c570b53ae44ec8e20106a518a5cd4346
hash \u00b7 361d8ac7fc72e97f796b82fcbc255d44c570b53ae44ec8e20106a518a5cd4346
Strange SQLAlchemy error message: TypeError: 'dict'… — DepScope fix | DepScope