【发布时间】:2019-08-16 22:39:20
【问题描述】:
我有兴趣删除 Redshift 架构中的所有表。即使这个解决方案有效
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;
不对我有好处,因为它也放弃了 SCHEMA 权限。
类似的解决方案
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 $$;
据此线程报告How can I drop all the tables in a PostgreSQL database?
将是理想的。不幸的是,它不适用于 Redshift(显然不支持 for loops)。
有没有其他解决方案来实现它?
【问题讨论】:
-
在集群外部用 python 或其他脚本语言编写循环?
标签: sql amazon-web-services amazon-redshift