1

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

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

1 Comment

thanks Gordon, works excellent. I added a Cross Join with generate_series to Retrieve records for all dates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.