Hello all i have the table
create table testpr(id serial,priority integer,unique(priority) DEFERRABLE, primary key(id)); and procedure: CREATE OR REPLACE FUNCTION JobPriorityChange(JobId bigint,NewPrior integer) RETURNS void AS $$ DECLARE PrevPrior integer; BEGIN PrevPrior := (select priority from testpr where id=JobId); if PrevPrior > NewPrior then WITH u as(update testpr set priority=NewPrior where id=JobId) update testpr set priority=priority+1 where priority>=NewPrior and priority<PrevPrior and id<>JobId; ELSIF PrevPrior < NewPrior then WITH u as(update testpr set priority=NewPrior where id=JobId) update testpr set priority=priority-1 where priority<=NewPrior and priority>PrevPrior and id<>JobId; END IF; END; $$ LANGUAGE plpgsql; according to: https://www.postgresql.org/docs/9.5/static/plpgsql-structure.html would you like to help me with several questions: 1)are all functions atomic? 2)are they execute in a single query? -- Arsen Arutyunyan