同一查询中两次更新的意外结果
Unexpected result for two updates in the same query
with
u1 as (
update todel set val=val+1 where id='key' returning *
),
u2 as (
update todel set val=val+2 where id='key' returning *
)
select * from u1
union all
select * from u2
;
预期结果是两行,但我得到了一行,
id | val
-----+-----
key | 11
为什么会这样,我错过了什么?服务器是 pg 9.6.6
The sub-statements in WITH are executed concurrently with each other and with the main query. Therefore, when using data-modifying statements in WITH, the order in which the specified updates actually happen is unpredictable.
结果好像只执行了一个
with
u1 as (
update todel set val=val+1 where id='key' returning *
),
u2 as (
update todel set val=val+2 where id='key' returning *
)
select * from u1
union all
select * from u2
;
预期结果是两行,但我得到了一行,
id | val
-----+-----
key | 11
为什么会这样,我错过了什么?服务器是 pg 9.6.6
The sub-statements in WITH are executed concurrently with each other and with the main query. Therefore, when using data-modifying statements in WITH, the order in which the specified updates actually happen is unpredictable.
结果好像只执行了一个