Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 批量更新场景问题
【TiDB Usage Environment】Production Environment
【TiDB Version】6.1
【Reproduction Path】
【Encountered Problem: Problem Phenomenon and Impact】
There is a batch update scenario in the business, and the TiDB community provides batch update statements Batch Update. This scenario updates columns that meet multiple conditions to the same value. The problem I am encountering now is whether it supports updating columns with multiple conditions to corresponding values:
create table example (id int primary key , val varchar(255) not null default '');
insert into example(id,val) values (1,'1'), (2,'2'), (3,'3');
select * from example
-- This is the currently supported syntax
update example set val = 'updated' where (id,val) in (1,'1'), (2,'2'), (3,'3')
-- Expected update method,
update example set ( val = 'update1' ), (val = 'update2') , (val = 'update3') where (id,val) in (1,'1'), (2,'2'), (3,'3')
I wonder if TiDB supports such multi-column updates with different values,
otherwise, the business can only perform updates in a loop.