我有以下脚本:
select txid_current();
显示的txid为=001
begin;
insert into tab values(10,20); insert into values(20,40);
commit;
现在当我这样做时: 选择 txid_current();
txid 看到的是:004 为什么增加 2 即为什么 txid 增加 2 不应该增加 1 即 txid 应该是 003 不应该选择 txid_current() 显示 003 ?
有没有办法将003显示为当前txid()?
最佳答案
<强> Transaction
PostgreSQL actually treats every SQL statement as being executed within a transaction. If you do not issue a BEGIN command, then each individual statement has an implicit BEGIN and (if successful) COMMIT wrapped around it. A group of statements surrounded by BEGIN and COMMIT is sometimes called a transaction block.
这意味着当您运行 select txid_current();
时,您就处于事务中,并且在运行之后您将获得新的事务 ID。
begin;
select txid_current(); // 1
end;
begin;
insert into tab values(10,20); insert into values(20,40);
select txid_current(); // 2
commit;
begin;
select txid_current(); // 3
end;
关于postgresql - 为什么txid会增加?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32611537/