Return Codes of BatchUpdateException in PostgreSql 9.6

From: Tillmann Schulz <tillmann73(at)yahoo(dot)de>
To: "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Return Codes of BatchUpdateException in PostgreSql 9.6
Date: 2016-10-13 08:25:24
Message-ID: 614642043.9384313.1476347124138@mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hello

I am migrating PostgreSql 9.5 to 9.6.0 and I am using the newest JDBC driver (9.4.1211.jre6)
So I am not sure if this is an driver issue or a bug in postgres.

We are making batch updates in our Java application.
Our JUnit Tests fail on 9.6 when querying the return code of a partially failed Batch Update.

If a statement of a batch update fails, all updateCounts are marked as failed.

In 9.5 everything works fine.

I try to give an example:

Preparation, with SQL
-----------------------------
create table TESTTABLE(id integer PRIMARY KEY) ;

INSERT INTO TESTTABLE VALUES (5);

Java Code with Java JDBC Update
-----------------------------

try{
for( int i = 0; i < 10;i++ )
{
stmt.addBatch("INSERT INTO TESTTABLE VALUES('"+i+"')" );
}
stmt.executeBatch();
con.commit();
}
catch( java.sql.BatchUpdateException x )
{
final int[] updateCounts = x.getUpdateCounts();

//==> in 9.5 only ther failed updates have return code java.sql.Statement.EXECUTE_FAILED = -3. This is CORRECT.

//==> in 9.6 all updatecounts have status java.sql.Statement.EXECUTE_FAILED = -3. This is NOT CORRECT.
}

In the sample, the 6th statement has an error, because the value 5 already exists in the database.

In this case in postgres 9.6 all fields updateCounts[0..9] are -3 (Statement.EXECUTE_FAILED)
The behavior prior 9.6 was, that only the specific entry in updateCounts[5] has the error code -3

Thank you for your help

Tillmann Schulz

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Victor Wagner 2016-10-13 09:53:58 Re: Patch: Implement failover on libpq connect level.
Previous Message Mithun Cy 2016-10-13 07:00:59 Re: Patch: Implement failover on libpq connect level.