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?

Reply via email to