Skip to content

Instantly share code, notes, and snippets.

@yuhangch
Created November 22, 2021 05:27
Show Gist options
  • Save yuhangch/6dc113d49bcdd0bf82bc7ae42ac33604 to your computer and use it in GitHub Desktop.
Save yuhangch/6dc113d49bcdd0bf82bc7ae42ac33604 to your computer and use it in GitHub Desktop.
Postgresql delete all table in a scheme exclude 'spatial_ref_sys'
DO $$ DECLARE
r RECORD;
BEGIN
FOR r IN (SELECT tablename FROM pg_tables WHERE (schemaname = current_schema() and tablename != 'spatial_ref_sys')) 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