postgresql – How to insert records using select statement?


Hi I am working on one project, here what I am trying is, I want to insert records what I get using select statements into temp table. but it is giving syntax error near select to me, can any one help me to solve this ?

following is my query

truncate table temp_mytbl;

 insert into temp_mytbl
select iex_id,dte,agent_name,schd_total
FROM source_xrx_iex6_sandy_1.iex6_agent_adh_sum 
--where dte = '2020-06-29'
--and iex_id = 52185337
group by iex_id,dte,agent_name,schd_total;

SELECT i.dte,
    idm.empl_id,
    1 AS entity_id,
    sum(i.schd_total) AS s_schdhours
   FROM temp_mytbl i
     JOIN mytest.test1 a ON a.winid = i.iex_id::text
     JOIN yourtest.test2 idm ON idm.src_id = a.agent_no AND idm.src_type_id = 618 AND soar_date(a.calendar_date_key) >= idm.start_dte AND soar_date(a.calendar_date_key) <= COALESCE(idm.end_dte, now()::date)
  GROUP BY i.dte, idm.empl_id limit 100;