Is it possible either to delete all rows from all tables with a single command in postgres (without destroying the database), or to cascade a delete in postgres?
If not, then how can I reset my test database?
is it possible either to delete all rows from all tables with a single command in postgres
You are right, the answer is NO
You can define cascading foreign keys that will delete all referencing rows if the "parent" is deleted. But that is an attribute of the foreign key, nothing you can specify with the DELETE statement
if not - wow.
What's that supposed to mean?
On second thought: what are you trying to achieve?
I have the suspicion that you are trying to "reset" e.g. a test database. In that case the PostgreSQL approach would be:
DROP DATABASE testdb
and then re-create the test database using CREATE DATABASE testdb TEMPLATE my_template
The newly created testdb will have all tables defined in my_template. That is probably a lot faster than deleting all rows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With