diff options
author | terminaldweller <devi@terminaldweller.com> | 2024-06-15 13:43:57 +0000 |
---|---|---|
committer | terminaldweller <devi@terminaldweller.com> | 2024-06-15 13:43:57 +0000 |
commit | 20f83572448187f806095ee0a8cc5b30bff72a93 (patch) | |
tree | 4c36696a6629b8dc6615fc6e98a67872923ce86d /scripts/entry_limit_trigger.sql | |
parent | added a shell.nix for pgformatter, and a wip trigger for db size maintenance (diff) | |
download | milla-20f83572448187f806095ee0a8cc5b30bff72a93.tar.gz milla-20f83572448187f806095ee0a8cc5b30bff72a93.zip |
added watchlists
Diffstat (limited to '')
-rw-r--r-- | scripts/entry_limit_trigger.sql | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/scripts/entry_limit_trigger.sql b/scripts/entry_limit_trigger.sql new file mode 100644 index 0000000..a3d4887 --- /dev/null +++ b/scripts/entry_limit_trigger.sql @@ -0,0 +1,27 @@ +create function remove_old_entries() + returns trigger + as $$ +begin + if( + select + COUNT(*) + from + table_name) > 10000 then + delete from table_name + where id in( + select + id + from + table_name + order by + id asc + limit 1000); + end if; + return null; +end; +$$ +language plpgsql; + +create trigger remove_old_entries_trigger + after insert on table_name for each row + execute procedure remove_old_entries(); |