Python批量插入问题?

Python批量插入问题?,第1张

s = 10000

list = []

c=0

sql = """insert into customer(id,name,company_id,sharding_id)

values(:col1,:col2,:col3,:col4)"""

for k in range(0,12):

i = 2000000 + k

list.append([i, 'haha'+str(i), i%5, s])

#list1.append([i, i, i, i])

if c == 10:

cursor = conn.cursor()

#print list

cursor.executemany(sql,list)

conn.commit()

c = 0

print("insert into customer many data cursor:"+str(i))

list=[]

c = c + 1

if s==10000:

s = 10010

elif s==10010:

s = 10020

elif s== 10020:

s = 10030

elif s==10030:

s = 10000

if i>0:

cursor.executemany(sql,list)

conn.commit()

程序调试通过,改了 2个地方

1.

sql = """insert into customer(id,name,company_id,sharding_id)

values(:col1,:col2,:col3,:col4)"""

2.list.clear()---》list=[]


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/7313672.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-04
下一篇2023-04-04

发表评论

登录后才能评论

评论列表(0条)

    保存