Trigger delete for old instances? #174
-
Is it possible to define a trigger which removes model instances after X days of last update? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Short answer is no - triggers are driven by events on the table, so this problem doesn't map very well. You could make a statement-level trigger on your table for any event, cleaning up old rows. This would impact performance whenever there is clean-up to do. Your data would remain uncleaned until there were events on the table. I would recommend a task scheduler here. If you want to keep all of this in Postgres and not something like Celery, you could consider the pgcron extension, which is supported by AWS and many other DB hosts |
Beta Was this translation helpful? Give feedback.
Short answer is no - triggers are driven by events on the table, so this problem doesn't map very well.
You could make a statement-level trigger on your table for any event, cleaning up old rows. This would impact performance whenever there is clean-up to do. Your data would remain uncleaned until there were events on the table.
I would recommend a task scheduler here. If you want to keep all of this in Postgres and not something like Celery, you could consider the pgcron extension, which is supported by AWS and many other DB hosts