I want to create a date range between two timestamps. I saw similar posts and also checked this method. However, still couldn't achieve the expected output below.
Please note that if ended_at
is NULL, then CURRENT_TIMESTAMP
needs to be taken.
Example data:
WITH t1 AS (
SELECT 'A' AS id, '2021-05-18 18:30:00'::timestamp AS started_at, '2021-05-19 09:45:00'::timestamp AS ended_at UNION ALL
SELECT 'B' AS id, '2021-05-24 11:30:40'::timestamp AS started_at, NULL::timestamp AS ended_at
)
SELECT *
FROM t1
Expected result: