Re: functions, transactions, key violations

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: functions, transactions, key violations
Date: 2008-06-04 22:21:28
Message-ID: 2CCF0182-0EA4-4416-B8F4-A9445A180A2D@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2008-06-04 22:30:43 Re: Script errors on run
Previous Message Ralph Smith 2008-06-04 22:12:49 Re: Script errors on run