【问题标题】:Postgres: Drop Table according to similar schema namePostgres:根据相似的模式名称删除表
【发布时间】:2014-03-20 14:52:08
【问题描述】:

我想从很多模式中删除一组表。 我要删除表的所有模式都以“pm_”开头。 我想从所有以“pm_”开头的模式中删除这组表。

类似的东西:

DROP TABLE IF EXISTS pm_%.tableName CASCADE;

(其中 % 将是名称的延续)。

【问题讨论】:

    标签: postgresql cascade sql-drop


    【解决方案1】:

    使用plpgsql,像这样:

    do $$ 
        declare schemaname text; 
        begin  
        for schemaname in select schema_name 
                         from information_schema.schemata 
                         where schema_name like 'pm\_%' 
                         loop 
            execute 'drop table if exists ' || quote_ident(schemaname) || '.tablename'; 
        end loop;  
    end $$;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-07
      • 2015-04-25
      • 2016-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-25
      • 1970-01-01
      相关资源
      最近更新 更多