【发布时间】:2018-11-12 02:00:32
【问题描述】:
这是我的脚本的一部分:
sql1 = """
SELECT distinct th.name, 'MMS' as Status
FROM t1
JOIN t2 on t1.id = t2.tid
WHERE t2.station= 'MatS'
AND t1.name IN ({listthinglist})
""".format(listthinglist=', '.join("'" + item + "'" for item in list_of_things))
cur.execute(sql1)
list_of_things 包含 22016 个项目,我无法在 python 中运行此查询。有没有其他方法可以在 python 中运行这样的查询。
【问题讨论】:
-
“无法运行”是什么意思?您是否看到错误消息?
-
您可以批量处理并在每次迭代时添加结果
-
@PatrickHaugh 我的猜测是查询字符串的大小比 DBMS 可以处理的要大。
-
创建一个临时表并使用它:stackoverflow.com/a/48392389/2681632。并且不要使用字符串格式将值传递给 SQL 查询。