Skip to content

Instantly share code, notes, and snippets.

@theory
Created October 1, 2019 20:39
Show Gist options
  • Save theory/8c320bde6494f19afcdbe93a1a72b828 to your computer and use it in GitHub Desktop.
Save theory/8c320bde6494f19afcdbe93a1a72b828 to your computer and use it in GitHub Desktop.
DO $$
DECLARE
target TEXT;
BEGIN
FOR target IN
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'bucardo'
AND table_name LIKE 'track_%'
LOOP
EXECUTE format(
'DELETE FROM bucardo.%I WHERE txntime < %L',
target, NOW() - '30 DAYS'::interval
);
EXECUTE format(
'DELETE FROM bucardo.%I WHERE txntime < %L',
replace(target, 'track', 'delta'),
NOW() - '30 DAYS'::interval
);
END LOOP;
END;
$$;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment