当前位置:网站首页>Two ways to deal with conflicting data in MySQL and PG Libraries
Two ways to deal with conflicting data in MySQL and PG Libraries
2022-04-23 13:41:00 【Wangcai 2】
mysql Processing mode
1.IGNORE
When using INSERT Statement adds some row data to the table and an error occurs during processing ,INSERT The statement will be aborted , And return an error message . therefore , No rows may be inserted into the table .
however , If you use INSERT INGORE sentence , The line that caused the error is ignored , And insert the remaining rows into the table .
insert IGNORE into table(xxx,xxx) VALUES (xxx,xxx);
insert IGNORE into `test` (`id`,`name`,`times`,`add_time`)
VALUES
('1','woq','3','1529304418'),
('2','woa','4','1529304452'),
('3','woz','5','1529304425'),
('4','wow','6','1529304445');
remarks :IGNORE When , If the data in the original result set is repeated, an error will be reported ,REPLACE The method will not report an error
2.REPLACE INTO
If you find that this row of data already exists in the table ( Based on the primary key or unique index ) Then delete this row of data first , Then insert the new data .
otherwise , Insert new data directly .
It should be noted that : The table that inserts data must have a primary key or a unique index ! Otherwise ,replace into Will insert data directly , This will result in duplicate data in the table .
REPLACE INTO table (xxx,xxx) VALUES (xxx,xxx);
REPLACE into `test` (`id`,`name`,`times`,`add_time`)
VALUES
('1','woq','3','1529304418'),
('2','woa','4','1529304452'),
('3','woz','5','1529304425'),
('4','wow','6','1529304445');
pg Library processing method
1. In case of conflicting data, do nothing
INSERT INTO customers (name, email)
VALUES
(
'Microsoft',
'[email protected]'
)
ON CONFLICT (name)
DO NOTHING;
2. Conflicting data update operation encountered
INSERT INTO customers (name, email)
VALUES
(
'Microsoft',
'[email protected]'
)
ON CONFLICT (name)
DO
UPDATE
SET email = EXCLUDED.email;
remarks :DO NOTHING When , If there is duplicate data in the original result set, no error will be reported ,DO UPDATE When , If there is duplicate data in the original result set, an error will be reported
版权声明
本文为[Wangcai 2]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230604300353.html
边栏推荐
- 鸿蒙系统是抄袭?还是未来?3分钟听完就懂的专业讲解
- [dynamic programming] 221 Largest Square
- Plato farm, a top-level metauniverse game, has made frequent positive moves recently
- Logstash数据处理服务的输入插件Input常见类型以及基本使用
- Zero copy technology
- According to the salary statistics of programmers in June 2021, the average salary is 15052 yuan. Are you holding back?
- 为什么从事云原生开发需要学习容器技术
- 【重心坐标插值、透视矫正插值】原理以及用法见解
- Launcher hides app icons that do not need to be displayed
- SAP UI5 应用开发教程之七十二 - SAP UI5 页面路由的动画效果设置
猜你喜欢

Machine learning -- PCA and LDA

@Excellent you! CSDN College Club President Recruitment!

缘结西安 | CSDN与西安思源学院签约,全面开启IT人才培养新篇章

叮~ 你的奖学金已到账!C认证企业奖学金名单出炉

为什么从事云原生开发需要学习容器技术

Opening: identification of double pointer instrument panel

According to the salary statistics of programmers in June 2021, the average salary is 15052 yuan. Are you holding back?

CSDN College Club "famous teacher college trip" -- Hunan Normal University Station

On the bug of JS regular test method
![[point cloud series] Introduction to scene recognition](/img/1f/c64712b03ae5b235b5dd3347c3e86a.png)
[point cloud series] Introduction to scene recognition
随机推荐
GDB的使用
Super 40W bonus pool waiting for you to fight! The second "Changsha bank Cup" Tencent yunqi innovation competition is hot!
[andorid] realize SPI communication between kernel and app through JNI
Explanation of input components in Chapter 16
Stack protector under armcc / GCC
[point cloud series] summary of papers related to implicit expression of point cloud
Tersus notes employee information 516 MySQL query (time period uniqueness judgment of 2 fields)
[point cloud series] so net: self organizing network for point cloud analysis
CSDN高校俱乐部“名师高校行”——湖南师范大学站
Machine learning -- naive Bayes
XML
[official announcement] Changsha software talent training base was established!
鸿蒙系统是抄袭?还是未来?3分钟听完就懂的专业讲解
Bottomsheetdialogfragment + viewpager + fragment + recyclerview sliding problem
【视频】线性回归中的贝叶斯推断与R语言预测工人工资数据|数据分享
POM of SSM integration xml
[Journal Conference Series] IEEE series template download guide
SAP UI5 应用开发教程之七十二 - SAP UI5 页面路由的动画效果设置试读版
缘结西安 | CSDN与西安思源学院签约,全面开启IT人才培养新篇章
[dynamic programming] 221 Largest Square