jrey
jrey

Reputation: 2183

postgres select all dates from interval

How to with Postgres I Could retrieve all dates using parameters 'from' and 'until'

example:

select date from 'maybe a system table' where date >= :from and date <= :to  

then te result is for (02-01-2015 and 05-01-2015)

 date
 ------------
 02-01-2015
 03-01-2015
 04-01-2015
 05-01-2015

What is the Best way to do this with Postgres, I know how to do with Oracle, but I need change my Database?? I Want to do a join with a table that does not have register with all dates and my report needs all days in one days interval

Regards

Upvotes: 1

Views: 1005

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269443

In Postgres, you can use generate_series(). Here is an example for the days in January, 2015:

select generate_series('2015-01-01'::timestamp, '2015-01-31'::timestamp,
                       '1 day')::date

Upvotes: 4

Related Questions