pg_current_xact_id_if_assigned()

一个返回当前事务ID(如果已分配)的函数

pg_current_xact_id_if_assigned() 是一个系统函数,用于返回当前事务ID(如果已分配)。

pg_current_xact_id_if_assigned()PostgreSQL 13 中添加。

用法

pg_current_xact_id_if_assigned () → xid8

pg_current_xact_id_if_assigned() 返回当前事务ID,类型为 xid8。请注意,在当前事务中执行非读操作之前,不会分配新的事务ID。

pg_current_xact_id_if_assigned() 替换了 txid_current_if_assigned()

变更历史

示例

pg_current_xact_id_if_assigned() 的基本用法示例 - 事务在修改数据库之前不会有事务ID

postgres=# BEGIN;
BEGIN

postgres=*# SELECT pg_current_xact_id_if_assigned();
 pg_current_xact_id_if_assigned 
--------------------------------
                               
(1 row)

postgres=*# SELECT 1;
 ?column? 
----------
        1
(1 row)

postgres=*# SELECT pg_current_xact_id_if_assigned();
 pg_current_xact_id_if_assigned 
--------------------------------
                               
(1 row)

postgres=*# INSERT INTO foo VALUES (1); 
INSERT 0 1

postgres=*# SELECT pg_current_xact_id_if_assigned();
 pg_current_xact_id_if_assigned 
--------------------------------
                            764
(1 row)

分类

系统函数, 事务

另请参阅

pg_current_xact_id(), pg_xact_status()

反馈

提交关于“pg_current_xact_id_if_assigned()”的任何评论、建议或更正,请在此处 提交