Skip to content

Instantly share code, notes, and snippets.

@kmoppel
Created January 11, 2017 08:58
Show Gist options
  • Save kmoppel/19fe74332a7369e765d5795248e7e086 to your computer and use it in GitHub Desktop.
Save kmoppel/19fe74332a7369e765d5795248e7e086 to your computer and use it in GitHub Desktop.
create table t_log (created_on timestamptz not null, event text);
create table t_log_archive (created_on timestamptz not null, event text);
insert into t_log select d, 'event' from generate_series(current_date-300, now(), '5m'::interval) d;
with q_sub as (delete from t_log where created_on < current_date - 30 returning *) insert into t_log_archive select * from q_sub;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment