我想在redshift中使用生成系列功能,但没有成功。
红移文档说它不受支持。以下代码确实有效:
select *
from generate_series(1,10,1)
输出:
1
2
3
...
10
我想对日期做同样的事情。我尝试了许多变体,包括:
select *
from generate_series(date('2008-10-01'),date('2008-10-10 00:00:00'),1)
踢出:
ERROR: function generate_series(date, date, integer) does not exist
Hint: No function matches the given name and argument types.
You may need to add explicit type casts. [SQL State=42883]
也试过:
select *
from generate_series('2008-10-01 00:00:00'::timestamp,
'2008-10-10 00:00:00'::timestamp,'1 day')
并尝试:
select *
from generate_series(cast('2008-10-01 00:00:00' as datetime),
cast('2008-10-10 00:00:00' as datetime),'1 day')
两者都踢出:
ERROR: function generate_series(timestamp without time zone, timestamp without time zone, "unknown") does not exist
Hint: No function matches the given name and argument types.
You may need to add explicit type casts. [SQL State=42883]
如果不是,我将使用另一篇文章中的此代码:
SELECT to_char(DATE '2008-01-01'
+ (interval '1 month' * generate_series(0,57)), 'YYYY-MM-DD') AS ym