pgadmin-org / pgagent

pgAgent - A job scheduler for PostgreSQL
https://www.pgadmin.org/
Other
97 stars 41 forks source link

SQL error in pgagent.pga_exception_trigger #2

Closed nhajek closed 5 years ago

nhajek commented 12 years ago

On PG 9.1 an SQL error is generated because the local variable is the same name as a column in a query, the following code corrects the issue.

CREATE OR REPLACE FUNCTION pgagent.pga_exception_trigger ( ) RETURNS trigger AS $body$ DECLARE

l_jobid int4 := 0;

BEGIN

 IF TG_OP = 'DELETE' THEN

    SELECT INTO l_jobid jscjobid FROM pgagent.pga_schedule WHERE jscid = OLD.jexscid;

    -- update pga_job from remaining schedules
    -- the actual calculation of jobnextrun will be performed in the trigger
    UPDATE pgagent.pga_job
       SET jobnextrun = NULL
     WHERE jobenabled AND jobid=l_jobid;
    RETURN OLD;
ELSE

    SELECT INTO l_jobid jscjobid FROM pgagent.pga_schedule WHERE jscid = NEW.jexscid;

    UPDATE pgagent.pga_job
       SET jobnextrun = NULL
     WHERE jobenabled AND jobid=l_jobid;
    RETURN NEW;
END IF;

END; $body$ LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER COST 100;

repo-lockdown[bot] commented 5 years ago

Thanks for your Pull Request! :smile: This repo on GitHub is just a mirror of our real git repositories though, and can't really handle PRs. :frowning: Hopefully you can redo the PR, and direct it to the git.postgresql.org repos? We have a developer guide, if that helps: https://wiki.postgresql.org/wiki/So,_you_want_to_be_a_developer%3F. If this was a PR for pgAdmin, please visit https://www.pgadmin.org/docs/pgadmin4/dev/submitting_patches.html.