Generate_series in Postgres from start and end date in a table
I have been trying to generate a series of dates (YYYY-MM-DD HH) from the first until the last date in a timestamp field. I've got the generate_series() I need, however running into an issue when trying to grab the start and end dates from a table. I have the following to give a rough idea: with date1 as ( SELECT start_timestamp as first_date FROM header_table ORDER BY start_timestamp DESC LIMIT 1 ), date2 as ( SELECT start_timestamp as first_date FROM header_table ORDER BY start_timestamp ASC LIMIT 1 ) select generate_series(date1.first_date, date2.first_date , '1 hour'::interval)::timestamp