UPDATE ... RETURNING atomicity

From: rihad <rihad(at)mail(dot)ru>
To: pgsql-general(at)postgresql(dot)org
Subject: UPDATE ... RETURNING atomicity
Date: 2010-05-23 06:15:43
Message-ID: 4BF8C80F.9010501@mail.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

In this query:
UPDATE foo
SET allocated_to=?
WHERE id=(SELECT MIN(id) FROM foo WHERE allocated_to IS NULL)
AND allocated_to IS NULL
RETURNING id

Is it guaranteed in any way that there will only be one id allocated and
returned even if multiple clients are executing this query concurrently?
Or is there a possibility that some other client executing this query
(or another query modifying allocated_to) might set allocated_to to
non-NULL and commit right after the inner select finds it as NULL, so
the outer "AND allocated_to IS NULL" will no longer be true, and the
outer query will return nothing?

Thanks.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Fetter 2010-05-23 08:55:58 Re: Moving from Mysql
Previous Message Craig Ringer 2010-05-23 05:17:30 Re: Full text search on a complex schema - a classic problem?