【问题标题】:PostgreSQL: what does pg_xact_commit_timestamp() return if the xid was from a failed transaction?PostgreSQL:如果 xid 来自失败的事务,那么 pg_xact_commit_timestamp() 会返回什么?
【发布时间】:2016-11-29 18:44:04
【问题描述】:
比如假设xid 6834是回滚,那么这个应该返回什么?
select pg_xact_commit_timestamp('6834'::xid);
文档中没有提到任何内容......似乎假设 xid 来自已提交的事务。所以我的问题是这种回滚事务的答案是稳定且有意义的吗?可以通过 select txid_current(); 从 BEGIN ... ROLLBACK uow 中获取此类 xid。
【问题讨论】:
标签:
postgresql
transactions
【解决方案1】:
它将返回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)