Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 为什么TXI会增加?_Postgresql_Psql - Fatal编程技术网

Postgresql 为什么TXI会增加?

Postgresql 为什么TXI会增加?,postgresql,psql,Postgresql,Psql,我有以下脚本: 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()show 003 是否有办法将003显示为当前txid(

我有以下脚本:

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()show 003

是否有办法将003显示为当前txid()?

PostgreSQL实际上将每个SQL语句都视为正在执行 在交易中。如果不发出BEGIN命令,则每个 单个语句有一个隐式的BEGIN和(如果成功)COMMIT 围绕着它。由BEGIN和BEGIN包围的一组语句 提交有时称为事务块

这意味着当您运行
选择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;

感谢您的澄清。我实际上是psql新手,因此尝试学习同样的内容。那么这是否意味着即使一个简单的select语句也只是一个事务,尽管它不会真正改变数据库?select txid_current()之间的区别是什么;并选择txid_current_snapshot()?为什么显示的是003而不是004?@MissJ。是的,正如我所悲伤的,每个SQL语句:)@MissJ。试着玩这个。只需运行select txid_current();几次,看看结果我确实明白你说的。。。我是plsql的新手,所以我想学同样的:)。。。选择txid_current()和;并选择txid_current_snapshot()?为什么显示的是003而不是004?