{"id":918,"hash":"361d8ac7fc72e97f796b82fcbc255d44c570b53ae44ec8e20106a518a5cd4346","pattern":"Strange SQLAlchemy error message: TypeError: &#39;dict&#39; object does not support indexing","full_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:\n\nsql = \"\"\"\n       SELECT DISTINCT u.name from user u\n        INNER JOIN city c ON u.city_id = c.id\n        WHERE c.designation=upper('fantasy') \n        AND c.id IN (select id from ref_geog where short_name LIKE '%opt')\n      \"\"\"\n\n# The last line in the above statement throws the error mentioned in the title. \n# However if the last line is change to:\n# AND c.id IN (select id from ref_geog where short_name = 'helloopt')\n# the script runs correctly.\n#\n# I also tried double escaping the '%' i.e. using '%%' instead - that generated the same error as previously.\n\nconnectDb()\nres = executeSql(sql)\nprint res\ncloseDbConnection()\n\nAny one knows what is causing this misleading error message and how I may fix it?\n\n[[Edit]]\n\nBefore 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.","ecosystem":"pypi","package_name":"postgresql","package_version":null,"solution":"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.\n\nSo when you want to place single % in string with query allways place double %.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/8657508/strange-sqlalchemy-error-message-typeerror-dict-object-does-not-support-inde","votes":208,"created_at":"2026-04-19T04:52:00.971173+00:00","updated_at":"2026-04-19T04:52:00.971173+00:00"}