Supabase | How to delete all tables in "public" schema

01kg

01kg

Posted on September 30, 2024

Supabase | How to delete all tables in "public" schema

TL;DR:

-- Drop all tables in a PostgreSQL schema (here is 'public' schema)
-- REF: https://supabase.com/docs/guides/database/postgres/dropping-all-tables-in-schema
do $$ declare
    r record;
begin
    for r in (select tablename from pg_tables where schemaname = 'public') loop
        execute 'drop table if exists ' || quote_ident(r.tablename) || ' cascade';
    end loop;
end $$;

Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
01kg
01kg

Posted on September 30, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024