Last active
August 29, 2015 14:17
-
-
Save sanderpick/f3b3f5918a7305f89038 to your computer and use it in GitHub Desktop.
TRIGGER: clear old data on INSERT
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
CREATE OR REPLACE FUNCTION clearOld() | |
RETURNS TRIGGER | |
AS $$ | |
BEGIN | |
DELETE FROM sf_muni_points WHERE created_at < now()-'1 day'::interval; | |
RETURN NEW; | |
END; | |
$$ language plpgsql; | |
CREATE TRIGGER clearOldOnInsert | |
AFTER INSERT ON sf_muni_points | |
FOR EACH STATEMENT | |
WHEN (pg_trigger_depth() = 0) | |
EXECUTE PROCEDURE clearOld(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment