Re: functions, transactions, key violations - Mailing list pgsql-general

From Michael Glaesemann
Subject Re: functions, transactions, key violations
Date
Msg-id 2CCF0182-0EA4-4416-B8F4-A9445A180A2D@seespotcode.net
Whole thread Raw
In response to Re: functions, transactions, key violations  (Jeff Davis <pgsql@j-davis.com>)
Responses Re: functions, transactions, key violations  (Jeff Davis <pgsql@j-davis.com>)
List pgsql-general
On Jun 4, 2008, at 6:00 PM, Jeff Davis wrote:

>> Some other concurrent transaction could still
> insert something after the UPDATE but before the INSERT, so the unique
> constraint violation can still occur.

Yes, I saw the comment. I'm guessing I'm missing something wrt
transaction isolation level or locking. Would I need to use
SERIALIZABLE or some kind of locking? Is the function in the example
any different than the following explicit transaction (with the UPDATE
not affecting any rows)?

BEGIN;
UPDATE db SET b = data WHERE a = key;
INSERT INTO db(a,b) VALUES (key, data);
COMMIT;

I'm obviously on the cusp of learning something new, or understanding
concurrency more deeply, so I'm looking forward to your responses.

Cheers,

Michael Glaesemann
grzm seespotcode net




pgsql-general by date:

Previous
From: Ralph Smith
Date:
Subject: Re: Script errors on run
Next
From: Stephan Szabo
Date:
Subject: Re: Script errors on run