我有桌面账户
create table account (
user_id int primary key,
acc int,
amt int
);
下一个数据
user_id | acc | amt
---------+------+-----
727 | 2620 | 10
777 | 2620 | 100
并且我想根据现有的 conreate acc 插入新行,如果与此 acc 存在并发插入,我想回滚事务
我尝试使用可序列化隔离级别:
T1
begin;
set transaction isolation level serializable;
insert into account (user_id, acc, amt)
values (-1, 2630, (select sum(sub.amt)
from account sub where sub.acc = 2620));
-- here T2 made an insert, but i didn't get expected serialization error
commit;
T2
insert into account(user_id, acc, amt)
values(737, 2620, 100);
结果没有冲突,但应该是。我错过了什么?
不存在序列化问题。逻辑上T2在T1之后,没有出现异常。