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屋!