Skip to content
Related Articles

Related Articles

Improve Article
PostgreSQL – TRUNCATE TABLE
  • Last Updated : 15 Feb, 2021

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:

My Personal Notes arrow_drop_up
Recommended Articles
Page :