此条目涉及一个 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() 取代。
变更历史
- PostgreSQL 13
- 标记为已弃用 (commit 4c04be9b)
- PostgreSQL 8.3
- 添加 (commit 1f92630f)
示例
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)
参考资料
- PostgreSQL 文档: 已弃用的事务 ID 和快照信息函数
