PostgreSQL – TRUNCATE TABLE
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.
First list all tables in the database using the below command:
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;