Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bufBn-0000nL-R9 for pgsql-jdbc@arkaria.postgresql.org; Thu, 13 Oct 2016 12:32:48 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bufBn-0002Va-ED for pgsql-jdbc@arkaria.postgresql.org; Thu, 13 Oct 2016 12:32:47 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bufBm-0002TO-HQ for pgsql-jdbc@postgresql.org; Thu, 13 Oct 2016 12:32:46 +0000 Received: from mail-pa0-x22e.google.com ([2607:f8b0:400e:c03::22e]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bufBk-0001sJ-1i for pgsql-jdbc@postgresql.org; Thu, 13 Oct 2016 12:32:45 +0000 Received: by mail-pa0-x22e.google.com with SMTP id vu5so38325503pab.0 for ; Thu, 13 Oct 2016 05:32:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:date:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZNHf86pUZTodzf6UlvME2V00TGJWmx56AGK6D+2alpM=; b=wuItTql1AIeA+IQYk/2flmmWiw3NQRkiXt8cnLlvfxV8u+tRuP1TjJQkW0eaaNBd8s 9JUKktpj4Z/PDncuCY/YS/HI2e+pVrI4e1i0yK753Q8xKioPGSWkmR3uwMNeo6fNHtKa sqIAD4/uJiS8D8lVNH/YznfYOuHTqu2G112vpW8fNQ84ZhTA+hmQY1nYKkQsaa7wQhO1 zPfbtKAbbwng5MLM+xR9Ckmh3yqSVcFSPvQaD3rRIsol+bhhoDfys6VTkjtrOWnUz/Cb kaPj0wNvCQuNYJwSZmSsydD71u+bFokdMzy/5Wrsmwvc/HbZ/Tvqsh6Q23cu56R7Pg/6 jOYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZNHf86pUZTodzf6UlvME2V00TGJWmx56AGK6D+2alpM=; b=Xtfol4ZZsITX+4H7KYMgDJcgJdYPrgcDHEmqkm/Zb9uwUZ51wW4E8XtVUXemRW74NL m9e7I/owmokexgVe1NjuHy68ZQJ3DP/vdH1xdYqrsE0M/Qb6p/mSh0Zk9PQWXeq+Jtjk gHqz+QjEJVKX3wyG9Xu9XeORWqDhzuabUmKKNt/VajFG07X6iTR2pPlo0H/xDJJATQW1 qiL8Gc1E4qHFwGr0SKd6XhcEpYU7b/V4SmKzDJsiTyCbt9z0y6wKy3LRdlrhNJS8uDT7 25Gm+cLQxWWlbTz0xzxTKjCEOeZGpJDE0evcVtg2nIi/5MvtNVPo4Cq0Zlw3eYUrp0wB Pjnw== X-Gm-Message-State: AA6/9RmBL+RZrlXjF2BDCialF3WlGPqbcMm1klo30tW8Mg4bsUz2+Fm/EA3YF3QDzkrkxw== X-Received: by 10.66.231.37 with SMTP id td5mr8111572pac.13.1476361962472; Thu, 13 Oct 2016 05:32:42 -0700 (PDT) Received: from roblaptop (58-7-141-150.dyn.iinet.net.au. [58.7.141.150]) by smtp.gmail.com with ESMTPSA id w15sm19499577pfi.47.2016.10.13.05.32.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Oct 2016 05:32:41 -0700 (PDT) Message-ID: <1476361957.3513.1.camel@gmail.com> Subject: Re: Return Codes of BatchUpdateException in PostgreSql 9.6 From: rob stone To: Tillmann Schulz , "pgsql-jdbc@postgresql.org" Date: Thu, 13 Oct 2016 23:32:37 +1100 In-Reply-To: <614642043.9384313.1476347124138@mail.yahoo.com> References: <614642043.9384313.1476347124138.ref@mail.yahoo.com> <614642043.9384313.1476347124138@mail.yahoo.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.0-2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org On Thu, 2016-10-13 at 08:25 +0000, Tillmann Schulz wrote: > 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 > > > According to the doco, getUpdateCounts():- Returns:     an array of int containing the update counts for the updates that were executed successfully before this error occurred. Or, if the driver continues to process commands after an error, one of the following for every command in the batch:    1.   an update count    2.   Statement.SUCCESS_NO_INFO to indicate that the command executed successfully but the number of rows affected is unknown    3.   Statement.EXECUTE_FAILED to indicate that the command failed to execute successfully  I do not know if the Postgres "driver continues to process commands after an error" but if it does then the array should contain 10 entries and one would have the "Statement.EXECUTE_FAILED". Tomorrow, I'll dig a bit deeper if nobody else can explain this. HTH, Rob -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc