假如是第2种,就可以用时间戳来比较,以下是例子
1。下载表的一个记录(不锁定)SELECT *, XMIN AS OLD_XMIN FROM XXX WHERE ...
2. 让客户端对这个缓冲进行交互式的修改
3. 提交更新时,
begin transaction;
select * , xmin as new_xmin from xxx where .... for update
if new_xmin <> old_xmin then
-- 已被他人修改,抛出错误或其他流程
rollback
else
update xxx set xxx=xxx where ...
commit
end
假如你的接口不接受xid数据类型, 可以将xid转换为integer,语句为cast(xmin as integer), 两者在postgresql内部都是同一类型, 不过xid 到 integer的类型转化不是postgresql内嵌的,所以还需要自定义这种转换
create cast (xid as integer) without function.
如果没有以上语句, cast(xmin as integer)可能不成功.
http://edu.codepub.com/2009/1130/18345.php