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