Open In App
Related Articles

PostgreSQL – TRUNCATE TABLE

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

In PostgreSQL, the TRUNCATE TABLE statement is used to instantly delete all content from tables. Though we have a DELETE statement to delete all data from a table that has a lot of data, but the TRUNCATE TABLE statement is more efficient.

Syntax: TRUNCATE TABLE table_name;

The TRUNCATE TABLE statement does not care about the table while deleting the same, simultaneously clearing the space for use by the user.

Example:

First list all tables in the database using the below command:

\dt

This will list all tables as depicted below:

The following example uses the TRUNCATE TABLE statement to delete all data from the foo table:

TRUNCATE TABLE foo;

Now if checked for the table again it will show that all data in the table is deleted as shown below:

SELECT  * FROM foo;

Output:


Last Updated : 15 Feb, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads