我正在尝试创建如下声明:
SELECT * FROM table WHERE provider IN ('provider1', 'provider2', ...)
但是,我在 Django API 的字符串格式方面遇到了一些问题。这是我到目前为止所拥有的:
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)')