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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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
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 testdband then re-create the test database usingCREATE DATABASE testdb TEMPLATE my_templateThe newly created testdb will have all tables defined in my_template. That is probably a lot faster than deleting all rows.