我有这种情况,我有这个名为 balance
的表:
id -> Integer Auto Increment not null
balance -> numeric(19) not null
date -> datetime default now() not null
id | balance | date
1 100 2019-09-12 16:15:29.091720
2 99 2019-09-12 16:15:33.404119
3 98 2019-09-12 16:15:33.412087
4 97 2019-09-12 16:15:33.425252
5 96 2019-09-12 16:15:33.442137
6 95 2019-09-12 16:15:33.513825 -> this time A
7 94 2019-09-12 16:15:33.444407 -> this time B
然后我只插入表中的 1 列,是平衡的。使用线程过程插入示例:
INSERT INTO balance(balance) VALUES(100)
日期B低于A,id增量为6后7,是否按id进行处理?
例如,id 6 是第一次处理然后插入 7。那么 6 的时间必须小于 7 吗?
知道为什么会这样吗?
最佳答案
如果插入 id = 7 行的事务开始早于插入 id = 6 的行,那么这是可能的。请注意,事务开始的时间很重要,而不是 insert
作为该事务的一部分执行的时间。
As documented in the manual , now()
返回交易开始的时间(与 transaction_timestamp()
相同,不是“当前”时间。
如果需要,您应该将默认值更改为 clock_timestamp()
关于postgresql - 不一致日期时间 PostgreSQL 默认值 now(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57904256/