表里面有主键为‘ 1234 ’,‘ 3456 ’的两个数据,现在用 Python 批量插入几条新数据 cursor.executemany(Insert into test ( id ) value(%s),('1234'),('6789'),(‘ 9876 ’)) 由于主键 1234 已经存在,这条代码回出错,同时 6789 、 9876 也会插入失败,有办法直接跳过 1234 这条数据,然后进行批量插入吗?
表里面有主键为‘ 1234 ’,‘ 3456 ’的两个数据,现在用 Python 批量插入几条新数据 cursor.executemany(Insert into test ( id ) value(%s),('1234'),('6789'),(‘ 9876 ’)) 由于主键 1234 已经存在,这条代码回出错,同时 6789 、 9876 也会插入失败,有办法直接跳过 1234 这条数据,然后进行批量插入吗?
|
lxyApr 7, 2016
1
insert ignore into ?
|
|
2
insert into xxxxx on duplicate key set xxx
|
|
fish267Apr 7, 2016
5
delete if exists
|
|
qile1Apr 7, 2016 via Android
6
先判断是否有主健,有就更新数据,没有就插入
|
|
NeveroldmilkApr 7, 2016
7
检索是否存在,如果存在要么更新,要么删除重新插入。
|
|
billgreen1Apr 7, 2016
8
insert into table on duplicate update
|
|
lunaticus7Apr 7, 2016
9
用 replace
|