generate_series() method fails in Redshift

前端 未结 7 1475
时光说笑
时光说笑 2020-11-27 22:01

When I run the SQL Query:

 select generate_series(0,g)
 from ( select date(date1) - date(date2) as g from mytable ;

It returns an error:

7条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 22:27

    The generate_series() function is not fully supported by Redshift. See the Unsupported PostgreSQL functions section of the developer guide:

    In the specific examples, the second query is executed entirely on the leader node as it does not need to scan any actual table data, while the first is trying to select data and as such would be executed on the compute node(s).

    UPDATE:

    generate_series is working with Redshift now.

    SELECT CURRENT_DATE::TIMESTAMP  - (i * interval '1 day') as date_datetime 
    FROM generate_series(1,31) i 
    ORDER BY 1
    

    This will generate date for last 30 days

提交回复
热议问题