当前位置:网站首页>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
边栏推荐
- Oracle kills the executing SQL
- Unified task distribution scheduling execution framework
- playwright控制本地谷歌浏览打开,并下载文件
- Esp32 vhci architecture sets scan mode for traditional Bluetooth, so that the device can be searched
- Uninstall MySQL database
- Interface idempotency problem
- Why do you need to learn container technology to engage in cloud native development
- Test on the time required for Oracle to delete data with delete
- Ai21 labs | standing on the shoulders of giant frozen language models
- Oracle generates millisecond timestamps
猜你喜欢

浅谈js正则之test方法bug篇

MySQL 8.0.11 download, install and connect tutorials using visualization tools

The interviewer dug a hole for me: how many concurrent TCP connections can a single server have?

How do ordinary college students get offers from big factories? Ao Bing teaches you one move to win!

Interface idempotency problem

Oracle defines self incrementing primary keys through triggers and sequences, and sets a scheduled task to insert a piece of data into the target table every second

You and the 42W bonus pool are one short of the "Changsha bank Cup" Tencent yunqi innovation competition!
![[Video] Bayesian inference in linear regression and R language prediction of workers' wage data | data sharing](/img/12/a330b5e77921bbfa8e96fcbc660daa.png)
[Video] Bayesian inference in linear regression and R language prediction of workers' wage data | data sharing

Solve the problem that Oracle needs to set IP every time in the virtual machine

Tersus notes employee information 516 MySQL query (time period uniqueness judgment of 2 fields)
随机推荐
联想拯救者Y9000X 2020
鸿蒙系统是抄袭?还是未来?3分钟听完就懂的专业讲解
Filter and listener of three web components
Plato farm, a top-level metauniverse game, has made frequent positive moves recently
Oracle defines self incrementing primary keys through triggers and sequences, and sets a scheduled task to insert a piece of data into the target table every second
Android clear app cache
Oracle index status query and index reconstruction
Oracle job scheduled task usage details
浅谈js正则之test方法bug篇
Comparison and summary of applicable scenarios of Clickhouse and MySQL database
Unified task distribution scheduling execution framework
The interviewer dug a hole for me: how many concurrent TCP connections can a single server have?
[andorid] realize SPI communication between kernel and app through JNI
torch. Where can transfer gradient
Lpddr4 notes
Oracle clear SQL cache
What do the raddr and rport in webrtc ice candidate mean?
Migrating your native/mobile application to Unified Plan/WebRTC 1.0 API
Common analog keys of ADB shell: keycode
Machine learning -- PCA and LDA