Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Snowflake Auto Purge records older than X number of days?

For an existing table in snowflake is there a way we can set TTL for each record ?

In other words can i ensure records updated/created more than 90 days ago is automatically purged periodically.

like image 261
Vinod Jayachandran Avatar asked Oct 16 '25 03:10

Vinod Jayachandran


2 Answers

You can use a Snowflake TASK to run deletes on a routine schedule:

CREATE OR REPLACE TASK PURGE
    WAREHOUSE = COMPUTE_WH
    SCHEDULE = '1 MINUTE'
    AS
    DELETE FROM MY_TABLE
    -- retention time
    WHERE LOAD_TIME < (CURRENT_TIMESTAMP - INTERVAL '90 DAYS');

If you are dealing with a very large table, I recommend that you cluster it on the DATE of whatever field you are using to delete from. This will increase the performance of the delete statement. Unfortunately, there is no way to set this on a table and have it remove records automatically for you.

like image 104
Mike Walton Avatar answered Oct 18 '25 23:10

Mike Walton


Opt 1. If the table is used for analytics, you can build a view on top of it to retrieve only last 90 days data (doing this you have the history) Opt 2. you can use SQL statement on schedule which deletes the records which are > 90 days

like image 37
sridark Avatar answered Oct 18 '25 23:10

sridark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!