我想在一个语句中更新Postgresql中的多行。有办法做一些像下面的事情吗?
UPDATE table SET column_a = 1 where column_b = '123',column_a = 2 where column_b = '345'
您还可以使用语法中的update …并使用映射表。如果你想更新多个列,它是更可通用:
update test as t set column_a = c.column_a from (values ('123',1),('345',2) ) as c(column_b,column_a) where c.column_b = t.column_b;
update test as t set column_a = c.column_a,column_c = c.column_c from (values ('123',1,'---'),2,'+++') ) as c(column_b,column_a,column_c) where c.column_b = t.column_b;