title: bulk insert from a query into table (postgresql)
body: <p>I cannot find an answer on this:</p>
  
  <p>I want to insert the result of this query into a table 'days':</p>
  
  <pre><code>WITH days AS ( 
  SELECT 
  date_part('dow',generate_series('2017-11-01','2017-11-30', interval '1 day')) as dow, 
  to_char(generate_series('2017-11-01','2017-11-30', interval '1 day'),'YYYY-MM-DD') as date ) 
  
  SELECT 0 as id,date, 
  CASE 
  WHEN dow=1 then 8 
  WHEN dow=2 then 8 
  WHEN dow=3 then 8 
  WHEN dow=4 then 8 
  WHEN dow=5 then 8 
  WHEN dow=6 then 0 
  WHEN dow=0 then 0 
  ELSE 0 END as wtime 
  FROM days
  </code></pre>
  
  <p>The table is as simple as this:</p>
  
  <pre><code>CREATE TABLE days
      (id serial, dates date, wtime numeric(8,2));
  </code></pre>
  
  <p>In my dreams it should look like this:</p>
  
  <pre><code>INSERT * INTO days FROM (
  
  WITH days AS ( 
  SELECT 
  date_part('dow',generate_series('2017-11-01','2017-11-30', interval '1 day')) as dow, 
  to_char(generate_series('2017-11-01','2017-11-30', interval '1 day'),'YYYY-MM-DD') as date ) 
  
  SELECT 0 as id,date, 
  CASE 
  WHEN dow=1 then 8 
  WHEN dow=2 then 8 
  WHEN dow=3 then 8 
  WHEN dow=4 then 8 
  WHEN dow=5 then 8 
  WHEN dow=6 then 0 
  WHEN dow=0 then 0 
  ELSE 0 END as wtime 
  FROM days)
  </code></pre>
  
  <p>Is this possible? How?</p>
  
  <p><a href="http://sqlfiddle.com/#!15/91c720/8" rel="nofollow noreferrer">http://sqlfiddle.com/#!15/91c720/8</a></p>