Create Temporary Table

A temporary table is a transient table that exists for the duration of a database session. Temporary tables are automatically dropped at the end of a session or transaction.

CREATE TEMPORARY TABLE temp_table_name(column_list );

**A Temporary table is only visible to the session that created it. In other words, it is invisible to other sessions.

PostgreSQL creates temporary tables in a custom schema, so you cannot specify the schema in the CREATE TEMP TABLE statement.

**If a permanent and temporary table is created with the same name, the temporary table is listed throughout the session.

CREATE TABLE musteri (id SERIAL PRIMARY KEY, name VARCHAR NOT
NULL);
CREATE TEMP TABLE musteri (customer_id INT );
Select * from musteri;

 

As seen in the above figure, the temp table column came as a result.

To delete the temporal table;

DROP TABLE temporary_table_name;