generate days from date range

后端 未结 29 2533
渐次进展
渐次进展 2020-11-21 05:19

I would like to run a query like

select ... as days where `date` is between \'2010-01-20\' and \'2010-01-24\'

And return data like:

29条回答
  •  猫巷女王i
    2020-11-21 06:20

    Accepted answer didn't work for PostgreSQL (syntax error at or near "a").

    The way you do this in PostgreSQL is by using generate_series function, i.e.:

    SELECT day::date
    FROM generate_series('2010-01-20', '2010-01-24', INTERVAL '1 day') day;
    
        day
    ------------
     2010-01-20
     2010-01-21
     2010-01-22
     2010-01-23
     2010-01-24
    (5 rows)
    

提交回复
热议问题