pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Wall <d.wall@computer.org>
To: pgsql-general@lists.postgresql.org
Subject: Re: For SELECT statement (just a reading one, no 'FOR UPDATE'), is COMMIT or ROLLBACK preferred?
Date: Sun, 25 Aug 2019 13:12:30 -0700
Message-ID: <bd843506-a7d9-6ab3-f4d8-2d6b592ddf0c@computer.org> (raw)
In-Reply-To: <3C2ED636-A81D-4BC4-92A1-38634F5DD5D2@gmail.com>
References: <3e16442c-a60a-679a-e72e-6d895552b6f8@computer.org>
	<3C2ED636-A81D-4BC4-92A1-38634F5DD5D2@gmail.com>

On 8/25/19 12:40 PM, Rob Sargent wrote
>> On Aug 25, 2019, at 1:09 PM, David Wall <d.wall@computer.org> wrote:
>>
>> Using the latest PostgreSQL, does it matter if my code does a ROLLBACK or a COMMIT on an non-modifying SELECT statement?  My impression is they'd be the same as nothing is changed and therefore there's nothing to commit or rollback, but wondered if there was any difference in how they are processed by Postgres?
>>
>> Thanks,
>> David
>>
>>
>>
> In interactive psql, both issue a warning that there is no current transaction.  What is your auto-commit setting and how is your code sent to the server?


We are accessing it via JDBC, and so we SQL via PreparedStatements 
against a Connection, and the connection is not auto-commit.  By 
default, the connection has a BEGIN TRANSACTION in place, so after all 
requests we do, we need to commit/rollback.  The main issue is that if 
we do a SELECT and get a ResultSet that has no rows, if we do a commit 
or a rollback, it seems reasonable that these are identical as no 
changes were made.  My inclination is to do a Connection.commit() on the 
connection because it wasn't in error or anything even if no rows were 
found, but wondered if a Connection.rollback() has any difference 
(positive/negative) in such a scenario.  We have SELECT sql statements 
that sometimes do a rollback after such queries because even though no 
rows was found is fine for SQL, it may be an issue in the application 
that expects there to be at least one row.  So we're trying to determine 
if there's actually any difference between commit/rollback after SELECT 
statements (with rows returned or not), a bit like if there's any 
difference for an UPDATE statement that returns zero rows were updated.








view thread (5+ messages)  latest in thread

Message-ID: <bd843506-a7d9-6ab3-f4d8-2d6b592ddf0c@computer.org>
Permalink:  ../bd843506-a7d9-6ab3-f4d8-2d6b592ddf0c@computer.org/
Also on:    postgresql.org/message-id/bd843506-a7d9-6ab3-f4d8-2d6b592ddf0c@computer.org

 · 

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-general@postgresql.org
  Cc: d.wall@computer.org
  Subject: Re: For SELECT statement (just a reading one, no 'FOR UPDATE'), is COMMIT or ROLLBACK preferred?
  In-Reply-To: <bd843506-a7d9-6ab3-f4d8-2d6b592ddf0c@computer.org>
  References: <3e16442c-a60a-679a-e72e-6d895552b6f8@computer.org> <3C2ED636-A81D-4BC4-92A1-38634F5DD5D2@gmail.com> <bd843506-a7d9-6ab3-f4d8-2d6b592ddf0c@computer.org>

* 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