From: Mark Rotteveel <mark@lawinegevaar.nl>
To: Andreas Joseph Krogh <andreas@visena.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: JDBC behaviour
Date: Thu, 18 Feb 2016 14:36:50 +0100
Message-ID: <954cc530fdaf2c5cf63dcb180d05fb56@imap.procolix.com> (raw)
In-Reply-To: <VisenaEmail.10e.692062643617cb13.152f4695802@tc7-visena>
References: <VisenaEmail.10e.692062643617cb13.152f4695802@tc7-visena>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>
On Thu, 18 Feb 2016 13:48:04 +0100 (CET), Andreas Joseph Krogh
<andreas@visena.com> wrote:
> I understand that and indeed this isn't something that should be
handled
> by the driver, however some of the response in this thread seem to
think
> it
> is an absurd expectation from the OP that failure of one statement
should
> still allow a commit. Which it isn't if you look at what other database
> systems do.
>
> Mark
>
> If that one failed statement doesn't raise an exception, how does the
> client
> (code) know that it failed? If it does raise an exception, then what
> standard
> specifies that that specific exceptions is to be treated as "don't
> rollback for
> this type of error"?
Of course an exception is raised, but the exact handling could then be
left to the client. For example the client could catch the exception,
decide based on the specific error to execute another statement to "fix"
the error condition and then commit. Think of INSERT, duplicate key, then
UPDATE before the existence of 'UPSERT'-like statements; if the occurrence
of duplicate key is rare it can be cheaper to do than to first SELECT to
check for existence and then INSERT or UPDATE, or to UPDATE, INSERT when
update count = 0. Another situation could be where the failure is not
important (eg it was only a log entry that is considered supporting, not
required), so the exception is ignored and the transaction as a whole is
committed.
Sure, in most cases it is abusing exceptions for flow control and likely
an example of bad design, but the point is that it is not outlandish to
allow execution of other statements and eventually a commit of a
transaction even if one or more statements failed in that transaction; as
demonstrated by systems that do allow this (for SQL Server you need to set
XACT_ABORT mode on to get similar behavior as PostgreSQL).
As to standards, for batch execution, JDBC expects that a driver either
process up to the first failure and raise a BatchUpdateException with the
update counts of the successfully executed statements, or continue
processing after failure(s) and only raise the exception after processing
the remainder of the batch (where the exception contains a mix of update
counts + failure indications). In both cases a commit for the statements
that were processed successfully would still be possible if the client so
wishes (see section 14.1.3 "Handling Failures during Execution" of JDBC
4.2).
Mark
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
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: mark@lawinegevaar.nl, andreas@visena.com
Subject: Re: JDBC behaviour
In-Reply-To: <954cc530fdaf2c5cf63dcb180d05fb56@imap.procolix.com>
References: <VisenaEmail.10e.692062643617cb13.152f4695802@tc7-visena> <954cc530fdaf2c5cf63dcb180d05fb56@imap.procolix.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