I cannot find an answer on this:
I want to insert the result of this query into a table 'days':
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
The table is as simple as this:
CREATE TABLE days
(id serial, dates date, wtime numeric(8,2));
In my dreams it should look like this:
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)
Is this possible? How?