Обсуждение: Stored procedure and transactions

Поиск
Список
Период
Сортировка

Stored procedure and transactions

От
inspector morse
Дата:
Hello,

I'm trying to figure out if the following stored procedure is safe in a high concurrency environment. I'm using the Postgresql 9.4 with all the default settings.

create procedure test(in topic_id int)
as
declare i_forum_id int;
declare i_post_tally int;
begin
     delete from forum_topics where topic_id = i_topic_id
     returning forum_id, post_tally into i_forum_id, i_post_tally;

     update forums set post_tally = post_tally - i_post_tally
     where forum_id = i_forum_id;
end;

If transaction #1 deletes the row from forum_topics and immediately after transaction #2 updates the post tally, will the update to the post_tally in transaction #1 be the correct value?

Re: Stored procedure and transactions

От
Robins Tharakan
Дата:

On 19 February 2015 at 06:39, inspector morse <inspectormorse86@gmail.com> wrote:
I'm trying to figure out if the following stored procedure is safe in a high concurrency environment.


PgAdmin-Support is for issues specific to PgAdmin.

Further, Concurrency is a relatively complicated topic, but more importantly I am not sure if PgAdmin-Support is the right place to request help for this query.

You should probably be looking at an appropriate PostgreSQL mailing lists for this query, although without putting in much thought / effort / input from your end, and without asking a query that isn't already clear in the docs, you'd be lucky to get the answer you're looking for.​

--
Robins Tharakan