我想在redshift中使用generate series函数,但尚未成功。在redshift中使用sql函数generate_series()
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
PostgreSQL generate_series() with SQL function as arguments
针对您的数据库运行'SELECT version()'来检索您的Postgres版本。 –
有关解决方法,请参阅:http://stackoverflow.com/a/34167753/3019685 – systemjack
我在此处发布了类似问题的解决方法https://stackoverflow.com/questions/22759980/generate-series-method-fails- in-redshift – AlexYes