我有一个2760000行的表。在mysqlworkbench中,从原始表中选择*需要36秒。在
我想用python中的这个现有表创建另一个表(使用myfunc()来转换值)。在
但是,当我在命令行中运行它时,它似乎永远不会结束。在
sql = "SELECT ID, Eye, Values FROM my_original_table"
curQuery.execute(sql)
for row in curQuery.fetchall():
dat = list(row)
id = dat.pop(0)
eye = dat.pop(0)
values = dat.pop(0)
v = my_func(values)
if v != None :
sql = "INSERT INTO new_table VALUES ( '%s', '%s', %d );" % (id, eye, v)
print(sql)
curExe.execute(sql)
db.commit()
但是,如果我在第一个select sql中添加了LIMIT 0,10(如下所示),它运行良好。所以,这意味着我的计划是正确的。但这是否意味着没有“限制”,数据太多,我的电脑无法处理?我怎么解决这个问题?在
^{pr2}$
根据documentation:
使用游标作为迭代器(不调用
fetchall
):以上相当于使用while循环处理查询,其中包含
^{pr2}$fetchone
:相关问题 更多 >
编程相关推荐