I have a table shown below (sample) and I want to create a new table with an extra column 'NewDate' which will look at StartDate and show the last date of the month for start date and subsequently last date of every month till the end date for each ID and if my ID has End Date as Null the series will stop at the last date of current month which is May 2022.
ID     StartDate      EndDate            
100     1/01/2022     26/04/2022    
101    20/04/2022     Null
102     1/01/2022     27/02/2022          
....
I am using Postgresql and my Expected Output:
ID  StartDate       EndDate          NewDate
100     1/01/2022    26/04/2022      31/01/2022
100     1/01/2022    26/04/2022      28/02/2022
100     1/01/2022    26/04/2022      31/03/2022
100     1/01/2022    26/04/2022      30/04/2022
101     20/04/2022    Null           30/04/2022
101     20/04/2022    Null           31/05/2022
102     1/01/2022    27/02/2022      31/01/2022
102     1/01/2022    27/02/2022      28/02/2022
...
 
    