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

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -