I have a postgres database schema with dozens of tables i need to drop. I essentially need to drop all the tables in my schema (abcd) with the word "group" in the name. How do i do that without manually going in and writing drop script for each one? Wondering if there is some easy way to do that in postgres sql? or maybe using python?
drop table abcd.group%;
select * from pg_class where relnamespace = 'abcd'::regnamespace and relname ilike 'group%'will get you tables starting with group. If you want group anywhere in name then '%group%'. You could then loop over those in Python or a Postgres function.