title: Generate_series in Postgres from start and end date in a table
body: <p>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 <code>generate_series()</code> 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:</p>
  
  <pre><code>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 as date_hour
  
  from
  (   select * from date1
      union
      select * from date2) as foo
  </code></pre>
  
  <p><strong>Postgres 9.3</strong></p>