postgresql - delete schemas with prefix -
i want delete schema within database starts 'u_', reason, keep getting on 200 schema created whenever try create , modify tables in pgsql.
i tried using
drop schema u_* cascade;
but don't think wildcards work (will syntax error code here). know can schema names through
select schema_name information_schema.schemata;
but there on don't know do. want delete schema either empty or start "u_".
this statement drop schemas names start u_
, contents:
do $$declare s text; begin s in select nspname pg_namespace nspname 'u\_%' loop execute 'drop schema "' || quote_ident(s) || '" cascade'; end loop; end;$$;
to drop empty schemas, use
do $$declare s text; begin s in select nspname pg_namespace nspname not 'pg_%' , nspname <> 'public' loop begin execute 'drop schema "' || quote_ident(s) || '"'; exception when others null; end; end loop; end;$$;
but if you, i'd figure out creates schemas , stop it. postgresql no such thing itself.
Comments
Post a Comment