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()
。
变更历史
- PostgreSQL 13
- added (commit 4c04be9b)
示例
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)
参考资料
- PostgreSQL documentation: 事务 ID 和快照信息函数