PostgreSQL:如果xid来自失败的事务,pg_xact_commit_timestamp()会返回什么?

时间:2016-11-29 05:05:39

标签: postgresql transactions

例如,假设xid 6834正在回滚,那么它应该返回什么?

select pg_xact_commit_timestamp('6834'::xid);

文档中没有提到......似乎假设xid来自已提交的事务。所以我的问题是这种回滚交易的答案是否稳定且有意义?可以通过例如select txid_current();内的BEGIN ... ROLLBACK获得此类xid。

1 个答案:

答案 0 :(得分:0)

它将返回NULL

test=> BEGIN;
BEGIN
test=> SELECT txid_current();
 txid_current
--------------
         1942
(1 row)

test=> ROLLBACK;
ROLLBACK
test=> select pg_xact_commit_timestamp('1942'::xid) IS NULL;
 ?column?
----------
 t
(1 row)