Skip to content

Instantly share code, notes, and snippets.

@linus-amg
Created January 12, 2023 18:13
Show Gist options
  • Select an option

  • Save linus-amg/4f273f57749a88f0cedfd209e66620cb to your computer and use it in GitHub Desktop.

Select an option

Save linus-amg/4f273f57749a88f0cedfd209e66620cb to your computer and use it in GitHub Desktop.

Revisions

  1. linus-amg created this gist Jan 12, 2023.
    8 changes: 8 additions & 0 deletions truncate.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    // this is dangerous, use with care, it truncates all tables in the current schema
    DO $$ DECLARE
    r RECORD;
    BEGIN
    FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP
    EXECUTE 'TRUNCATE TABLE ' || quote_ident(r.tablename) || ' CASCADE';
    END LOOP;
    END $$;