为了防止旧版本覆盖新版本,在这个简单的函数中:
create function myupdate(paramts timestamp without time zone, ...)
language plpgsql AS
$$
begin
-- step 1 compare current record timestamp vs. supplied timestamp
if exists (select 1 from record where ts <> paramts and ...) then
raise exception 'A newer version exists, cannot update.';
end if;
...
end
$$;
ts
定义是一样的timestamp without time zone
.
paramts
值由函数提供:
create function myfetch(...)
language plpgsql AS
$$
begin
return query select ts, ... from record where ...;
end
$$;
Node API 和 Angular 客户端 UI 得到的是2021-04-16T21:37:35.878Z提交给的值也是如此myupdate()
。然而,在我们的西海岸服务器之一上,在执行期间myupdate()
, ts
自动转换为 PST2021-04-16 14:37:35.878694右边多了 3 位数字。
如何比较 UTC 和相同精度?
你应该使用timestamptz
(timestamp with time zone
)代替timestamp
(timestamp without time zone
)以避免任何时区混淆。在餐桌上,在功能上,在整个食物链中。然后,值始终在内部存储为 UTC 时间,并且比较会自动正确进行(比较独立于时区的时间点)。
See:
- 在 Rails 和 PostgreSQL 中完全忽略时区 https://stackoverflow.com/questions/9571392/ignoring-time-zones-altogether-in-rails-and-postgresql/9576170#9576170
无论哪种方式,两种类型都有微秒分辨率,即6派系十进制数字。您的第一个示例以某种方式被截断,可能是由您的客户端在显示中截断的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)