9951 explained code solutions for 126 technologies


postgresqlHow do I truncate a table in PostgreSQL?


To truncate a table in PostgreSQL, you can use the TRUNCATE command. This command removes all rows from the table quickly and efficiently.

Example code

TRUNCATE TABLE my_table;

The code above will remove all rows from the table my_table. No output will be returned.

The TRUNCATE command has the following parts:

  • TRUNCATE - the command to truncate a table
  • TABLE - specifies that you are truncating a table
  • my_table - the name of the table you are truncating

For more information, please see the PostgreSQL documentation.

Edit this code on GitHub