Skip to content

Instantly share code, notes, and snippets.

@mchung
Created March 16, 2023 22:30
Show Gist options
  • Save mchung/3f10456d64d1178fb2bbac6513ed3e46 to your computer and use it in GitHub Desktop.
Save mchung/3f10456d64d1178fb2bbac6513ed3e46 to your computer and use it in GitHub Desktop.
DO
$$
DECLARE
s name;
t name;
rowc bigint;
BEGIN
FOR s, t IN select table_schema, table_name
from information_schema.tables
where table_name NOT LIKE 'pg_%'
AND table_name NOT LIKE 'fivetran_audit'
AND table_schema LIKE 'a_prefix_here_%'
LOOP
EXECUTE format('delete from %I.%I where _fivetran_deleted = true', s, t);
EXECUTE format('select count(*) from %I.%I where _fivetran_deleted = true', s, t) into rowc;
raise notice '%.%: % rows', s, t, rowc;
END LOOP;
END;
$$ LANGUAGE plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment