Below we will create a task that runs every minute, with a step that calls some SQL:
do $$ declare job_id int; begin insert into pgagent.pga_job (jobjclid, jobname) values (1 , 'my job name') returning jobid into job_id; insert into pgagent.pga_jobstep (jstjobid, jstname, jstkind, jstcode, jstdbname) values ( job_id, 'my step name', 's', 'select * from thing', 'mydb' ); insert into pgagent.pga_schedule (jscjobid, jscname) values (job_id, 'my schedule name'); end $$;
source share