Re: Does a the block of code within a stored procedure constitute a transaction?

From: <btober(at)seaworthysys(dot)com>
To: <rbt(at)rbt(dot)ca>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Does a the block of code within a stored procedure constitute a transaction?
Date: 2003-08-01 01:28:18
Message-ID: 65027.66.212.203.144.1059701298.squirrel@$HOSTNAME
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

>> What I need to know is whether or not this is multi-user safe, i.e.,
>> will the block of code in the procedure execute as a transaction so
>> that if more than one clerk creates an expense report for the same
>> employee simultaneously is it possible or impossible that value of
>> the
>> employee.expense_report_seq gets updated by the second clerk between
>> the SELECT and UPDATE statements invoked by the first clerk?
>>
>> And as a follow-up, should I add the FOR UPDATE clause to the SELECT
>> statement?
>
> SELECT .. FOR UPDATE would be appropriate.
>
> However, you could also do an update + 1 first and the select second to
> find what you changed the value to.

Yes, and I like the fact that the UPDATE first approach eliminates a
local variable declaration as well!

~Berend Tober

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Christoph Haller 2003-08-01 11:25:00 Re: length of recordset read through a cursor
Previous Message Eric Johnson 2003-08-01 00:54:45 Using contrib/fulltext on multiple tables