2017-11-24 19 views
0

現在、いくつかのデータベースに複数のエクステンションのコピーがインストールされています。具体的には、パブリックスキーマからのみ削除したいtablefunc関数のコピーが複数存在します。Postgresql - 特定のスキーマからのドロップエクステンション

extensions schema 
    functions 
    colpivot(... 
    crosstab(... 
    ... 
public schema 
    functions 
    colpivot(... 
    crosstab(... 
    ... 

パブリックスキーマからすべてのtablefunc拡張機能を削除するにはどうすればよいですか?
DROP EXTENSION tablefunc;私の場合は、機能を拡張スキーマから削除するだけです(達成したいものの反対)。もちろん、これは複数のデータベースと拡張機能によって広がっています。そのため、拡張名をターゲットにして、さまざまなコマンドをすべてハードコードしないでください。DROP FUNCTION...

+1

一つの小さな質問:どのようにあなたが延長のいくつかのコピーを作成しましたか? Newerはこれまでに試しましたが、別のスキーマで既存の拡張を作成しようとすると、PostgreSQLは次のように言っています: "ERROR:extension" tablefunc "already exists" – Abelisto

答えて

1

することができます答えは実際にはなく、ここで開始することではありません。

with obj_list as (
    select 
    case when p.oid is not null then 'p' when t.oid is not null then 't' end as tp, 
    case when p.oid is not null then p.oid::regprocedure::text when t.oid is not null then t.typname end as def, 
    d.objid 
    from pg_depend d left join pg_proc p on (d.objid = p.oid) left join pg_type t on (d.objid = t.oid) 
    where refobjid = (select oid from pg_extension where extname = 'tablefunc' /* extension name here */)) 
select 
    case tp when 't' then 'drop type ' when 'p' then 'drop function ' end || 'public.' || def || ';' as drop_stmt 
from obj_list 
order by objid desc /* reverse object creation order to saticfy dependencies */; 

出力:

┌──────────────────────────────────────────────────────────────────────────────┐ 
│         drop_stmt         │ 
╞══════════════════════════════════════════════════════════════════════════════╡ 
│ drop function public.connectby(text,text,text,text,text,integer);   │ 
│ drop function public.connectby(text,text,text,text,text,integer,text);  │ 
│ drop function public.connectby(text,text,text,text,integer);     │ 
│ drop function public.connectby(text,text,text,text,integer,text);   │ 
│ drop function public.crosstab(text,text);         │ 
│ drop function public.crosstab(text,integer);         │ 
│ drop function public.crosstab4(text);          │ 
│ drop function public.crosstab3(text);          │ 
│ drop function public.crosstab2(text);          │ 
│ drop type public.tablefunc_crosstab_4;          │ 
│ drop type public.tablefunc_crosstab_3;          │ 
│ drop type public.tablefunc_crosstab_2;          │ 
│ drop function public.crosstab(text);           │ 
│ drop function public.normal_rand(integer,double precision,double precision); │ 
└──────────────────────────────────────────────────────────────────────────────┘ 
関連する問題