Postgresql: when temporary tables are deleted in postgresql
In fact you created a regular table. You have to specify that this is a temporary table:

with cte as(
-- &lt;a_query&gt;
)
select * 
into temporary temp_table
from cte;


or (the recommended syntax):

create temporary table temp_table as
-- &lt;a_query&gt;


See SELECT INTO and CREATE TABLE AS.