I have some tables in schema public's;
I want destroy all tables at schema. Like DROP TABLE public.*
I have some tables in schema public's;
I want destroy all tables at schema. Like DROP TABLE public.*
I usually do it like this (I've commented execution of the query, it will only be printed):
do $$
declare
rec record;
query text;
begin
for rec in select * from pg_tables where schemaname = 'public'
loop
query = format('drop table %s.%s', rec.schemaname, rec.tablename);
raise notice '%', query;
--execute query;
end loop;
end
$$ language plpgsql;
I use cool DO thing when I just want to execute some code but don't want to create a stored procedure.
If all of the tables are in the same schema (public):
DROP SCHEMA public CASCADE;
CREATE SCHEMA public;