How do I drop all tables whose name start with, say, doors_
? Can I do some sort of regex using the drop table
command?
I prefer not writing
I normally use one query to generate the DDL commands for me based on some of the metadata tables and then run those commands manually. For example:
SELECT 'DROP TABLE ' || tablename || ';' FROM pg_tables
WHERE tablename LIKE 'prefix%' AND schemaname = 'public';
This will return a bunch of DROP TABLE xxx;
queries, which I simply copy&paste to the console. While you could add some code to execute them automatically, I prefer to run them on my own.