Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save anilktechie/6458db4a72841a20310afb09a2201fc5 to your computer and use it in GitHub Desktop.

Select an option

Save anilktechie/6458db4a72841a20310afb09a2201fc5 to your computer and use it in GitHub Desktop.

Revisions

  1. @kagundajm kagundajm revised this gist Oct 18, 2020. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion postgresql-drop-all-tables.sql
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,11 @@ DO $$
    r RECORD;
    BEGIN
    FOR r IN
    (SELECT table_name FROM information_schema.tables WHERE table_schema=current_schema();)
    (
    SELECT table_name
    FROM information_schema.tables
    WHERE table_schema=current_schema()
    )
    LOOP
    EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.table_name) || ' CASCADE';
    END LOOP;
  2. @kagundajm kagundajm revised this gist Oct 18, 2020. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions postgresql-drop-all-tables.sql
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,10 @@
    DO $$
    DECLARE r RECORD;
    DECLARE
    r RECORD;
    BEGIN
    FOR r IN
    (SELECT tablename FROM pg_tables WHERE schemaname = current_schema())
    (SELECT table_name FROM information_schema.tables WHERE table_schema=current_schema();)
    LOOP
    EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE';
    EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.table_name) || ' CASCADE';
    END LOOP;
    END $$ ;
  3. @kagundajm kagundajm created this gist Oct 18, 2020.
    9 changes: 9 additions & 0 deletions postgresql-drop-all-tables.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    DO $$
    DECLARE r RECORD;
    BEGIN
    FOR r IN
    (SELECT tablename FROM pg_tables WHERE schemaname = current_schema())
    LOOP
    EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE';
    END LOOP;
    END $$ ;