【问题标题】:Is it possible to query for the last few hours of data using a timestamp in Redshift?是否可以使用 Redshift 中的时间戳查询最近几个小时的数据?
【发布时间】:2014-12-19 23:42:39
【问题描述】:

我正在尝试编写查询来查找最近 2 小时的数据。

我最初尝试使用 INTERVAL:

select count(*) from data where created_at > CURRENT_TIMESTAMP - (INTERVAL '2 hours');

但我得到一个未实现的错误:

错误:未实施
详情:
-----------------------------------------------------------
错误:未实现代码:1001
上下文:'!null_tst' - 函数:timestamp_gt_timestamptz(),funcID = 2523
查询:2734016
位置:cg_expr.cpp:295
进程:padbmaster [pid=25255]
-----------------------------------------------------------

有人知道在 Redshift 中不使用绝对时间戳的方法吗?

【问题讨论】:

  • 你试过 dateadd(h, -2, now) 吗?
  • dateadd(hour, -12, getdate()) 似乎有效。不知道我是怎么错过的。谢谢!

标签: amazon-redshift


【解决方案1】:
SELECT  count(*)
FROM    data
WHERE   created_at >= 
dateadd(day/or_other_parameter,0,CURRENT_TIMESTAMP) - '2 hr'::INTERVAL

使用 dateadd 函数可以轻松搞定

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-01
    • 2020-11-06
    • 2014-08-14
    • 1970-01-01
    • 2021-04-07
    • 1970-01-01
    • 1970-01-01
    • 2022-10-13
    相关资源
    最近更新 更多