递归删除postgresql数据库中所有表

DO $$ DECLARE
    r RECORD;
BEGIN
    -- if the schema you operate on is not"current", you will want to
    -- replace current_schema() in query with 'schematodeletetablesfrom'
    -- *and* update the generate 'DROP...' accordingly.
    FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP
        EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE';
    END LOOP;
END $$;

参考:https://blog.csdn.net/boveysmith/article/details/106155761

posted @ 2021-01-30 09:35  柔南青空  阅读(445)  评论(0编辑  收藏  举报