From 20f83572448187f806095ee0a8cc5b30bff72a93 Mon Sep 17 00:00:00 2001 From: terminaldweller Date: Sat, 15 Jun 2024 09:43:57 -0400 Subject: added watchlists --- scripts/entry_limit_trigger.sql | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 scripts/entry_limit_trigger.sql (limited to 'scripts/entry_limit_trigger.sql') 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(); -- cgit v1.2.3