Transactions and functions

Поиск
Список
Период
Сортировка
От Арсен Арутюнян
Тема Transactions and functions
Дата
Msg-id 1474645442.389960547@f336.i.mail.ru
обсуждение исходный текст
Ответы Re: Transactions and functions  (Adrian Klaver <adrian.klaver@aklaver.com>)
Re: Transactions and functions  (amul sul <sulamul@gmail.com>)
Список pgsql-general
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

В списке pgsql-general по дате отправления:

Предыдущее
От: Deven Phillips
Дата:
Сообщение: Re: jsonb_set for nested new item?
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: Transactions and functions