IN clause with integers in sqlalchemy/psycopg2

postgresql, python, sql

Solution

I ended up ditching SqlAlchemy for straight psycopg2, so I don't know if it applies 100%. What I found out was that psycopg2 will correctly compile the IN clause if you pass it a tuple rather than an array/list. I passed a tuple of integers and it worked just fine.

Problem

Just a beginner with the python/postgres combo so forgive me if this is trivial. I'm executing a raw SQL query with sqlalchemy along the lines of: ``` SELECT * FROM table WHERE pk_table_id IN () ``` For the example below I tried `self.ids` as a tuple containing string or integers as well as an array containing string or integers. Either way it didn't work. When I use this line: ``` my_connection.execute('SELECT * FROM public.table WHERE pk_table_id IN (%s)', self.ids) ``` I get the error: ``` TypeError: not all arguments converted during string formatting ``` Any suggestions?

Original source

Related problems