Today I Learned

hashrocket A Hashrocket project

Truncate All Rows

Given a postgres database, if you want to delete all rows in a table, you can use the DELETE query without any conditions.

> delete from pokemons;

Though DELETE can do the job, if you really are deleting all rows to clear out a table, you are better off using TRUNCATE. A TRUNCATE query will be faster than a DELETE query because it will just delete the rows without scanning them as it goes.

> truncate pokemons;


See More #sql TILs
Looking for help? Hashrocket developers believe that data quality is as important as code quality. We enjoy all the challenges of relational databases, from finding the fastest index, to structuring data to fit the needs of an application. We're eager to share our experiences; check out PG Casts, our series of free PostgreSQL screencasts.