Re: Problem JDBC, AutoCommit ON and SELECT FOR UPDATE

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: Problem JDBC, AutoCommit ON and SELECT FOR UPDATE
Дата
Msg-id 54F9E6E2.9030106@aklaver.com
обсуждение исходный текст
Ответ на Problem JDBC, AutoCommit ON and SELECT FOR UPDATE  (Philippe EMERIAUD <p.emeriaud@ordirope.fr>)
Список pgsql-general
On 03/06/2015 08:27 AM, Philippe EMERIAUD wrote:
> Hi all,
> We have an application based on DB2 database, We are testing this same
> application on PostgreSQL database. By default we are in autocommit on
> mode.
> On DB2 (and Oracle), the query SELECT FOR UPDATE locks the row until the
> resultset is closed. On PostgreSQL database (all versions) this same
> query never locks (because we are in autocommit on mode). But this is a
> bad implementation of JDBC specification : "If a connection is in
> auto-commit mode, then all its SQL statements will be executed and
> committed as individual transactions.[...] The commit occurs when the
> statement completes or the next execute occurs, whichever comes first.
> In the case of statements returning a ResultSet object, the statement
> completes when the last row of the ResultSet object has been retrieved
> or the ResultSet object has been closed."
> Is it possible to lock row in autocommit on mode on PostgreSQL database ?

I am not following. So you have:

BEGIN;
SELECT FOR UPDATE ...;
COMMIT;

The SELECT FOR UPDATE will lock the rows while doing the SELECT and then
release when it the COMMIT happens. So barring an error the lock will
hold for the time it takes to do the SELECT and process the COMMIT.

Do you want the lock to hold past the COMMIT?

--
Adrian Klaver
adrian.klaver@aklaver.com


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

Предыдущее
От: Philippe EMERIAUD
Дата:
Сообщение: Problem JDBC, AutoCommit ON and SELECT FOR UPDATE
Следующее
От: Dave Cramer
Дата:
Сообщение: Re: Problem JDBC, AutoCommit ON and SELECT FOR UPDATE