【问题标题】:Comparing time in text format in psql 12在 psql 12 中比较文本格式的时间
【发布时间】:2020-09-08 09:29:47
【问题描述】:
SELECT *
FROM   lighting
WHERE  cast("time" as timestamp) BETWEEN '23:55:00'::timestamp
AND now();

但我得到如下错误:

ERROR: column "23:55:00::timestamp" does not exist LINE 3: WHERE cast("time" as timestamp) BETWEEN "23:55:00::timestam...

我的“时间”栏是如下文本格式的

05:50:53
06:58:38
07:30:42

我做错了什么?

【问题讨论】:

  • 查询和报错信息不一致。查询有'23:55:00'::timestamp,而错误显示"23:55:00::timestamp"
  • 您的字段"time" 的值似乎为time,无法转换为timestamp,如果您只想比较时间,则可以使用time 代替timestamp 和 'current_time' 代替 now()

标签: postgresql psql pgadmin-4 postgresql-12


【解决方案1】:

您的字段“时间”的值似乎为time,无法转换为timestamp

所以试试这个方法:

SELECT *
FROM   lighting
WHERE  cast("time" as time) BETWEEN '23:55:00'::time
AND current_time;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多