now() 默认值都显示相同的时间戳 [英] now() default values are all showing same timestamp
问题描述
我已经用一列(类型:带时区的时间戳)创建了我的表,并将其默认值设置为 now()
(current_timestamp()
).
I have created my tables with a column (type: timestamp with timezone) and set its default value to now()
(current_timestamp()
).
我在单个函数的单独语句中运行了一系列插入,我注意到所有时间戳都等于 (ms),函数值是否以某种方式缓存并为整个函数调用或事务共享?
I run a series of inserts in separate statements in a single function and I noticed all the timestamps are equal down to the (ms), is the function value somehow cached and shared for the entire function call or transaction?
推荐答案
即 预期和记录行为:
来自手册:
由于这些函数返回的是当前事务的开始时间,因此它们的值在事务期间不会改变.这被认为是一个特性:其意图是允许单个事务具有一致的当前"时间概念,以便同一事务内的多个修改具有相同的时间戳.
如果你想要每次运行语句时都改变一些东西,你需要使用 statement_timestamp()
甚至 clock_timestamp()
(再次参见手册中的描述)
If you want something that changes each time you run a statement, you need to use statement_timestamp()
or even clock_timestamp()
(again see the description in the manual)
这篇关于now() 默认值都显示相同的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!