Skip to content

Instantly share code, notes, and snippets.

@BacLuc
Created August 11, 2025 12:48
Show Gist options
  • Select an option

  • Save BacLuc/61a0ece302e81fd1473e461741fdf215 to your computer and use it in GitHub Desktop.

Select an option

Save BacLuc/61a0ece302e81fd1473e461741fdf215 to your computer and use it in GitHub Desktop.
DO $$ DECLARE
r RECORD;
BEGIN
FOR r IN (
SELECT tablename as entry
FROM pg_tables
WHERE
schemaname = current_schema())
LOOP
EXECUTE 'DROP TABLE ' || quote_ident(r.entry) || ' CASCADE';
END LOOP;
END $$;
DO $$ DECLARE
r RECORD;
BEGIN
FOR r IN (
SELECT sequencename as entry
FROM pg_sequences
WHERE
schemaname = current_schema())
LOOP
EXECUTE 'DROP SEQUENCE ' || quote_ident(r.entry) || '';
END LOOP;
END $$;
DO $$ DECLARE
r RECORD;
BEGIN
FOR r IN (
SELECT viewname as entry
FROM pg_views
WHERE
schemaname = current_schema())
LOOP
EXECUTE 'DROP VIEW ' || quote_ident(r.entry) || '';
END LOOP;
END $$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment