i have a table like bellow in postgres
start_at | end_at |
---|---|
17/1/2023 | 15/3/2023 |
i want to split this like bellow
start_at | end_at |
---|---|
17/1/2023 | 31/1/2023 |
01/2/2023 | 28/2/2023 |
1/3/2023 | 15/3/2023 |
I have tried generate series of postgres but not able to generate desire row. Please someone help me
2
Answers
Recommended Solution(h/t: Prosenjit Chongder):
The solution using
generate_series
function is much more compact.Fiddle
Older Solution:
You will need a recursive Common table expression to acheive your purpose.
outputs:
DBFiddle
The following will generate the described results:
Results: