Skip to content
Advertisement

Date range to row in postgres

I have a table in postgres like this:

id open_date close_date
5 2006-08-04 2019-12-31

There exist 4897 days between them. I need to turn the date range to date to have one record per day. For example:

id open_date close_date valid_date
5 2006-08-04 2019-12-31 2006-08-04
5 2006-08-04 2019-12-31 2006-08-05
5 2006-08-04 2019-12-31 2006-08-06
………. ………. ……….
5 2006-08-04 2019-12-31 2019-12-31

I tried the query provided here like this:

The TAB1 contains 600 rows. After running this query it produce correct records but only max 600 records for each id. This means for this date range only till 2008-06-08

Advertisement

Answer

In Postgres, you would use generate_series():

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement