Skip to content

Instantly share code, notes, and snippets.

@anhtran
Created September 5, 2022 12:51
Show Gist options
  • Save anhtran/8b79e4e79161126394282e7e4a0334ef to your computer and use it in GitHub Desktop.
Save anhtran/8b79e4e79161126394282e7e4a0334ef to your computer and use it in GitHub Desktop.
Drop all tables with prefix use wildcard - Xóa toàn bộ bảng bắt đầu bằng tiền tố bất kỳ trong PostgreSQL (psql)
# remove all tables start with "django_"
DO $$ DECLARE
r RECORD;
BEGIN
FOR r IN (SELECT tablename FROM pg_tables WHERE tablename like 'django_%') LOOP
EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE';
END LOOP;
END $$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment