【发布时间】:2020-09-16 17:39:39
【问题描述】:
列 created_at, modified_at 类型 timestamp 没有时区
以毫秒为单位在此列中获取增量:
select extract(milliseconds from modified_at - created_at) as delta_millsfrom shop_order
很好。现在我想获取增量当前日期和列 created_at
我试试这个:
select id, extract(milliseconds from (EXTRACT(EPOCH FROM current_timestamp) * 1000) - created_at) as detla_mills from shop_order
但报错
:
ERROR: operator does not exist: double precision - timestamp without time zone
LINE 1: ...om (EXTRACT(EPOCH FROM current_timestamp) * 1000) - created_...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
SQL state: 42883
Character: 85
【问题讨论】:
-
只看第二个表达式的语法,我对从
current_timestamp提取的EPOCH应用的* 1000很怀疑。我怀疑它会导致正确的timestamp类型。鉴于抱怨双精度减去时间戳的错误消息,我猜想乘法会给你一个double,你不能直接从中减去timestamp。也许有办法将其转换回timestamp? -
@RobParker 这项工作:选择 id, created_at, extract(milliseconds from (CURRENT_TIMESTAMP) - created_at) 作为 shop_order 的增量
-
我应该把我的评论作为答案然后获得信用吗?我没有,因为我不特别了解 PostgreSQL,也无法给出有效的示例解决方案......只是意识到错误在语法中抱怨的内容的提示。
标签: postgresql-9.5