database - Delete all Contents from postgreSQL -
i have database lots of tables.
is there way clear contents of tables without each table! mean way iterate database tables list , delete contents.
thanx help.
a simple database function iterates on tables in schema , clear content. warning: function clear tables without asking if sure :) use caution! no warranty!
create or replace function clear_tables_in_schema(_schemaname text)returns void $$ declare _tablename text; begin _tablename in select tablename pg_catalog.pg_tables schemaname = _schemaname loop raise info 'clearing table %.%', _schemaname, _tablename ; execute format('truncate %i.%i cascade;', _schemaname, _tablename); end loop; if not found raise warning 'schema % not exist', _schemaname; end if; end; $$ language plpgsql; -- usage: select clear_tables_in_schema('your_schema');
Comments
Post a Comment