当前位置:网站首页>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
边栏推荐
- 2021年6月程序员工资统计,平均15052元,你拖后腿了吗?
- Operations related to Oracle partition
- Oracle renames objects
- [point cloud series] Introduction to scene recognition
- Using open to open a file in JNI returns a - 1 problem
- 零拷贝技术
- Unified task distribution scheduling execution framework
- [tensorflow] sharing mechanism
- 鸿蒙系统是抄袭?还是未来?3分钟听完就懂的专业讲解
- TIA博途中基於高速計數器觸發中斷OB40實現定點加工動作的具體方法示例
猜你喜欢
【视频】线性回归中的贝叶斯推断与R语言预测工人工资数据|数据分享
Lenovo Savior y9000x 2020
[barycentric coordinate interpolation, perspective correction interpolation] principle and usage opinions
切线空间(tangent space)
UEFI learning 01-arm aarch64 compilation, armplatformpripeicore (SEC)
[point cloud series] full revolutionary geometric features
Usereducer basic usage
面试官给我挖坑:单台服务器并发TCP连接数到底可以有多少 ?
On the bug of JS regular test method
Cross carbon market and Web3 to achieve renewable transformation
随机推荐
Use of GDB
Utilisation de GDB
Launcher hides app icons that do not need to be displayed
交叉碳市场和 Web3 以实现再生变革
面试官给我挖坑:单台服务器并发TCP连接数到底可以有多少 ?
Oracle creates tablespaces and modifies user default tablespaces
Explanation of input components in Chapter 16
[Video] Bayesian inference in linear regression and R language prediction of workers' wage data | data sharing
The difference between string and character array in C language
叮~ 你的奖学金已到账!C认证企业奖学金名单出炉
[tensorflow] sharing mechanism
XML
Oracle view related
SAP UI5 应用开发教程之七十二 - SAP UI5 页面路由的动画效果设置
Error 403 in most cases, you or one of your dependencies are requesting
Common commands of ADB shell
Common analog keys of ADB shell: keycode
LeetCode_ DFS_ Medium_ 695. Maximum area of the island
Riscv MMU overview
Ding ~ your scholarship has arrived! C certified enterprise scholarship list released