加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql – now()默认值都显示相同的时间戳

发布时间:2020-12-13 16:43:12 所属栏目:百科 来源:网络整理
导读:我创建了我的表与列(类型:时间戳与时区),并将其默认值设置为now()(current_timestamp())。 我在单个函数中在单独的语句中运行一系列插入,我注意到所有的时间戳都等于(ms),是以某种方式缓存并为整个函数调用或事务共享的函数值? 这是 expected and docum
我创建了我的表与列(类型:时间戳与时区),并将其默认值设置为now()(current_timestamp())。

我在单个函数中在单独的语句中运行一系列插入,我注意到所有的时间戳都等于(ms),是以某种方式缓存并为整个函数调用或事务共享的函数值?

这是 expected and documented的行为:

从手册:

Since these functions return the start time of the current transaction,their values do not change during the transaction. This is considered a feature: the intent is to allow a single transaction to have a consistent notion of the “current” time,so that multiple modifications within the same transaction bear the same time stamp.

如果你想要每次运行语句时发生变化,你需要使用statement_timestamp()或甚至clock_timestamp()(再次参见手册中的描述)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读