blob: a3d4887da7292aee673ad17946ea3d8b1776974d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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();
|