How to drop multiple tables in PostgreSQL using a wildcard

前端 未结 7 1949
闹比i
闹比i 2020-12-13 05:39

When working with partitions, there is often a need to delete all partitions at once.

However

DROP TABLE tablename*

Does not work.

相关标签:
7条回答
  • 2020-12-13 06:16

    Here's another hackish answer to this problem. It works in ubuntu and maybe some other os too. do a \dt in postgres command prompt(the command prompt was running inside genome-terminal in my case). Then you'll see a lot of tables in the terminal. Now use ctrl+click-drag functionality of the genome-terminal to copy all tables' names. enter image description hereOpen python, do some string processing(replace ' ' by '' and then '\n' by ',') and you get comma separated list of all tables. Now in psql shell do a drop table CTRL+SHIFT+V and you're done. I know it's too specific I just wanted to share. :)

    0 讨论(0)
提交回复
热议问题