Re: transaction

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: transaction
Дата
Msg-id 20040421180242.GB30712@wolff.to
обсуждение исходный текст
Ответ на transaction  ("H.J. Sanders" <hjs@worldonline.nl>)
Список pgsql-sql
On Wed, Apr 21, 2004 at 12:58:56 +0530, denis@coralindia.com wrote:
> 
> The code looks like:
> 
>         update tempxitag set qty = qty + nqty where
>                 ccod = cccod
>         GET DIAGNOSTICS nFound = ROW_COUNT;
>         If nFound = 0 then
>             insert into tempxitag( ccod, qty)
>             values (cccod, nqty );
>         End if;

You still can get errors if two transactions try to refer to the same
nonexistant record at the same time. Postgres doesn't do predicate
locking so the update won't lock the to be inserted row and both
transactions may see the record as not existing and both try to do
an insert.

Updating, checking the count and then trying an insert if the count was
0 and retrying if the insert fails may be a better approach than locking
the table. However, since this is an existing application it may be hard
to make this complicated of a change.

If there is flexibility in how the task gets done, switching to something
based on sequences is probably the way to go.


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

Предыдущее
От:
Дата:
Сообщение: Trigger calling a function HELP ME! (2)
Следующее
От: Heflin
Дата:
Сообщение: Join issue on a maximum value