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(
-- <a_query>
)
select * 
into temporary temp_table
from cte;

or (the recommended syntax):

create temporary table temp_table as
-- <a_query>

See SELECT INTO and CREATE TABLE AS.


According to Postgres documentation temporary tables are dropped at end of a session or at end of a transaction.

TEMPORARY or TEMP

If specified, the table is created as a temporary table. Temporary tables are automatically dropped at the end of a session, or optionally at the end of the current transaction (see ON COMMIT below). Existing permanent tables with the same name are not visible to the current session while the temporary table exists, unless they are referenced with schema-qualified names. Any indexes created on a temporary table are automatically temporary as well.