Hi I started to explore pgAgent recently. Installation and testing had been done. However, there is one thing that bothers me about pgAgent. the thing will only run either SQL or batch code.
Suppose, in my database table contains different week number data. for maintenance purpose, the table should store only past 2 weeks data. Would pgAgent capable to do the automation of this task.
the workflow will be:
1)Get System timestamp
2)Calculate week Number
3)delete * from table where week= week - 3
if this can be done, Would it be on the batch or SQL kind?? I highly appreciate if you can provide some example.
Thank you so much.
CREATE OR REPLACE FUNCTION weekno() RETURNS void AS $$
DECLARE weekno INTEGER;
BEGIN
weekno := select extract(week from (select current_timestamp));
RAISE NOTICE '%', weekno;
END;
$$ LANGUAGE plpgsql;
SELECT weekno();
delete * from mytable where week=weekno();
Example, Assuming select extract(week from (select current_timestamp)) returns 22, then the row containing week 19 data must be deleted.
Week Person Total Overtime Hours
19 Belle 12
19 Anthony 10
19 Boss 0
20 Anthony 15
20 Boss 0
20 Belle 5
21 Anthony 20
21 Belle 10
21 Boss 0
22 Anthony 25
22 Belle 8
22 Boss 0