我创建了我的表与列(类型:时间戳与时区),并将其默认值设置为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()(再次参见手册中的描述)