PostgreSQL – Empty a Table (Delete, Truncate)

To empty a table by removing all the rows, you can either use Delete or Truncate.

DROP table drops the table from the database. Whereas, Both Delete and Truncate removes just the data from the table leaving behind an empty table.

Syntax:

TRUNCATE TABLE table_name;
DELETE FROM table_name;

DELETE is a DML statement, Whereas TRUNCATE is a DDL statement.

You can specify a WHERE clause with DELETE statement to remove only rows that satisfy the condition in WHERE clause. TRUNCATE always removes all the rows of a table.

See also  PostgreSQL - Change Column datatype