I am trying to create an instruction as follows:
SELECT * FROM table WHERE provider IN ('provider1', 'provider2', ...)
However, I am having problems formatting the string from the Django API. Here is what I still have:
profile = request.user.get_profile() providers = profile.provider.values_list('provider', flat=True) # [u'provider1', u'provider2'] providers = tuple[str(item) for item in providers] # ('provider1', 'provider2') SQL = "SELECT * FROM table WHERE provider IN %s" args = (providers,) cursor.execute(sql,args) DatabaseError (1241, 'Operand should contain 1 column(s)')
source share