【问题标题】:ERROR: column "event_start_adj" is of type timestamp without time zone but expression is of type interval错误:列“event_start_adj”的类型是没有时区的时间戳,但表达式的类型是间隔
【发布时间】:2023-03-14 10:39:01
【问题描述】:

我目前正在插入/更新列上没有时区数据的随机时间戳,但 PostgreSQL 不断给我错误 ERROR: column "event_start_adj" is of type timestamp without time zone but expression is of type interval 并且提示说:HINT: You will need to rewrite or cast the expression.

我的查询:

UPDATE dashboard.event SET event_start_adj = (random() * ('2020-01-01 00:00:00'::timestamp without time zone - '2020-04-16 23:59:59'::timestamp without time zone )) WHERE event_id = 2286 

任何帮助将不胜感激..

【问题讨论】:

标签: sql postgresql


【解决方案1】:

您收到此错误是因为您的查询结果是一个间隔而不是时间戳。您需要添加第一个日期做间隔以获得时间戳。

UPDATE dashboard.event SET event_start_adj = '2020-01-01 00:00:00'::timestamp + (random() * ('2020-01-01 00:00:00'::timestamp without time zone - '2020-04-16 23:59:59'::timestamp without time zone )) WHERE event_id = 2286

【讨论】:

    猜你喜欢
    • 2020-02-17
    • 2021-06-18
    • 2015-11-09
    • 2015-11-26
    • 1970-01-01
    • 2019-11-08
    • 2021-12-27
    • 1970-01-01
    • 2018-12-31
    相关资源
    最近更新 更多