【问题标题】:Time difference in query查询时差
【发布时间】:2020-11-03 06:35:52
【问题描述】:

我正在尝试运行此查询以查找某些字段形式的 redshift 和额外的列作为时差。下面我提到了我正在尝试执行的查询。

select gtfs.t_stops_gtfs.*, gtfs.t_stop_times_gtfs.departure_time, '${currentTime}' as current_time, 
   datediff(minute, gtfs.t_stop_times_gtfs.departure_time, '${currentTime}') as td from gtfs.t_stops_gtfs 
   join gtfs.t_stop_times_gtfs on gtfs.t_stops_gtfs.stop_id = gtfs.t_stop_times_gtfs.stop_id limit 3

我得到的错误是

函数 pg_catalog.date_diff("unknown", character varying, "unknown") 不存在

知道这有什么问题。

因为这条线datediff(minute, gtfs.t_stop_times_gtfs.departure_time, '${currentTime}') as td而出现错误

离开时间的样本值:'18:25:00',当前时间:'06:34:39'`。

【问题讨论】:

    标签: sql date amazon-redshift


    【解决方案1】:

    来自doc 的 datediff 函数需要两个时间戳或日期时间作为输入。正如您在错误中看到的那样,传递的gtfs.t_stop_times_gtfs.departure_time 被解析为字符串,而'${currentTime}' 的类型未知。您要做的就是将它们转换为日期或时间戳,例如:

    datediff(minute, gtfs.t_stop_times_gtfs.departure_time::date, '${currentTime}'::date)
    

    【讨论】:

      猜你喜欢
      • 2017-07-17
      • 1970-01-01
      • 1970-01-01
      • 2022-10-14
      • 2022-11-04
      • 2011-08-07
      • 2015-02-23
      • 2022-12-19
      • 2021-09-06
      相关资源
      最近更新 更多