Open In App

PostgreSQL - Removing Temporary Table

Last Updated : 15 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
In PostgreSQL, one can drop a temporary table by the use of the DROP TABLE statement.
Syntax: DROP TABLE temp_table_name;
Unlike the CREATE TABLE statement, the DROP TABLE statement does not have the TEMP or TEMPORARY keyword created specifically for temporary tables. To demonstrate the process of dropping a temporary table let's first create one by following the below instructions. First, we create a sample database(say, test) to add a temporary table using the below statement:
CREATE DATABASE test;
After creating the database we switch into it using the following command:
\c test;
Now we add a temporary table (say, mytemp) to the test database as below:
CREATE TABLE mytemp(c INT);
Verify if the table has been created using the below statement:
SELECT * FROM mytemp;
It should show you the below table: Now that our temporary table is created we remove it in the below example. Example: We use the DROP TABLE statement inside the database test as follows to drop the temporary table:
DROP TABLE mytemp;
Now we verify if the table has been removed successfully using the below statement:
SELECT * FROM mytemp;
Output: The above-shown error raised by PostgreSQL shows that the mytemp table doesn't exist anymore.

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy