Skip to content

Instantly share code, notes, and snippets.

@erubboli
Created September 3, 2014 10:33
Show Gist options
  • Save erubboli/86aab08ea3983345132e to your computer and use it in GitHub Desktop.
Save erubboli/86aab08ea3983345132e to your computer and use it in GitHub Desktop.
archiving using CTE (pg)
WITH archive AS (
DELETE FROM arrivals
WHERE created_at < now() - interval '1 hours'
RETURNING *
)
INSERT INTO archived_arrivals
SELECT * FROM archive;
DELETE FROM archived_arrivals
WHERE created_at < now() - interval '3 days';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment