【发布时间】:2019-10-13 10:44:53
【问题描述】:
我正在尝试进行多次更新,但它仅适用于第一行。
我的表“用户”有 2 条记录:
create table users
(
uid serial not null
constraint users_pkey
primary key,
balance numeric default 0 not null
);
INSERT INTO public.users (uid, balance) VALUES (2, 100);
INSERT INTO public.users (uid, balance) VALUES (1, 100);
我尝试使用查询更新用户“1”两次,但它只更新一次: 用户“1”的余额变为“105”,而不是“115”
update users as u
set balance = balance + c.bal
from (values (1, 5),
(1, 10)
) as c(uid, bal)
where c.uid = u.uid;
为什么它没有更新子查询中的所有行?
【问题讨论】:
标签: postgresql join sql-update