Postgresql: when temporary tables are deleted in postgresql I am inserting data into temp table and its working fine. below is the psedo sql code for the same

with cte as(

)
select * 
into temp_table
from cte


with this approach data is inserted very fast into temp table. As per my knowleged temp table is deleted once the session is closed. but my temp table is not deleted even if closed my pgadmin connection.

My question is does temp table in postgresql are deleted automatically or they remains on disk space until we delete them.

Regards,

Sanjay Salunkhe
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.