txid_current_if_assigned()

返回已分配的当前事务 ID 的函数
此条目涉及一个 PostgreSQL 功能,该功能已弃用,并可能在未来的版本中不再支持。

txid_current_if_assigned() 是一个系统函数,返回已分配的当前事务 ID。

txid_current_if_assigned()PostgreSQL 8.3 中添加。

用法

txid_current_if_assigned () → bigint

txid_current_if_assigned()bigint 的形式返回当前事务 ID。请注意,在当前事务中执行非只读查询之前,不会分配新的事务 ID。

此函数在 PostgreSQL 13 中引入 xid8 数据类型后已被弃用,并被 pg_current_xact_id_if_assigned() 取代。

变更历史

示例

txid_current_if_assigned() 的基本用法示例 - 事务在对数据库进行更改之前不会有事务 ID

postgres=# BEGIN;
BEGIN

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

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

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

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

postgres=*# SELECT txid_current_if_assigned();
 txid_current_if_assigned 
--------------------------
                      742
(1 row)

分类

已弃用, 系统函数, 事务

另请参阅

pg_current_xact_id_if_assigned(), txid_current()

反馈

对“txid_current_if_assigned()”的任何评论、建议或更正,请在此 提交