Created
September 3, 2014 10:33
-
-
Save erubboli/86aab08ea3983345132e to your computer and use it in GitHub Desktop.
archiving using CTE (pg)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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