DO $$ DECLARE
    r RECORD;
BEGIN
    FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = 'temp') LOOP
        EXECUTE 'DROP TABLE IF EXISTS temp.' || quote_ident(r.tablename) || ' CASCADE';
    END LOOP;
END $$;