pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Philippe EMERIAUD <p.emeriaud@ordirope.fr>
To: pgsql-general@postgresql.org
Subject: Re: Problem JDBC,  AutoCommit ON and SELECT FOR UPDATE
Date: Fri, 06 Mar 2015 09:41:54 -0800
Message-ID: <54F9E6E2.9030106@aklaver.com> (raw)
In-Reply-To: <OF493CD29D.2988C2D6-ONC1257E00.005A174C-C1257E00.005A7021@ordirope.fr>
References: <OF493CD29D.2988C2D6-ONC1257E00.005A174C-C1257E00.005A7021@ordirope.fr>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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


-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



view thread (5+ messages)  latest in thread

Message-ID: <54F9E6E2.9030106@aklaver.com>
Permalink:  ../54F9E6E2.9030106@aklaver.com/
Also on:    postgresql.org/message-id/54F9E6E2.9030106@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: adrian.klaver@aklaver.com, p.emeriaud@ordirope.fr, pgsql-general@postgresql.org
  Subject: Re: Problem JDBC,  AutoCommit ON and SELECT FOR UPDATE
  In-Reply-To: <54F9E6E2.9030106@aklaver.com>
  References: <OF493CD29D.2988C2D6-ONC1257E00.005A174C-C1257E00.005A7021@ordirope.fr> <54F9E6E2.9030106@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox