【发布时间】:2016-09-29 10:02:48
【问题描述】:
我在 Redshift 中有一个表,其中包含一个日期列和一些其他数据:
+------------+-------+
| Date | Value |
+------------+-------+
| 2016-09-25 | 1 |
| 2016-09-28 | 2 |
| 2016-09-29 | 3 |
+------------+-------+
我想从此表中获取“缺失”的日期。因此,从上面的示例中,如果我想获取从 7 天前到现在的所有缺失日期,我想生成一个返回的查询:
2016-09-22
2016-09-23
2016-09-24
2016-09-26
2016-09-27
我尝试使用 generate_series(..) 函数来生成所有日期,然后将它们过滤掉以查找表中已经存在的日期。所以,类似:
select CURRENT_DATE + i as MyDate
from generate_series(date '2016-09-22'- CURRENT_DATE, date '2016-09-29' - CURRENT_DATE ) i
where MyDate not in (select [Date] from MyTable)
在这种情况下,我遇到错误“我的日期”不存在。我也尝试过使用 and EXCEPT 子句,然后产生错误:
INFO: Function "generate_series(integer,integer)" not supported.
[Err] ERROR: Specified types or functions (one per INFO message) not supported on Redshift tables.
我尝试过的各种其他事情都会产生该错误,我可以单独运行 generate_series(..) 但如果我尝试使用任何其他子句等,它就会失败。
这在 Redshift 中可以实现吗?
【问题讨论】:
标签: sql database postgresql amazon-redshift