Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YbSP8-0000Nb-5D for pgsql-jdbc@arkaria.postgresql.org; Fri, 27 Mar 2015 11:26:22 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YbSP7-0003y8-Gn for pgsql-jdbc@arkaria.postgresql.org; Fri, 27 Mar 2015 11:26:21 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YbSP6-0003y1-HK for pgsql-jdbc@postgresql.org; Fri, 27 Mar 2015 11:26:20 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YbSOx-0008HV-Qv for pgsql-jdbc@postgresql.org; Fri, 27 Mar 2015 11:26:18 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t2RBQ8j6022498 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 27 Mar 2015 07:26:09 -0400 Received: from [10.36.116.38] (ovpn-116-38.ams2.redhat.com [10.36.116.38]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t2RBQ7ZI015541 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 27 Mar 2015 07:26:08 -0400 Message-ID: <55153E4D.2020201@redhat.com> Date: Fri, 27 Mar 2015 11:26:05 +0000 From: Jeremy Whiting User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: Multi insert statement and getUpdateCount(). References: <551434D9.6040906@redhat.com> <551460E2.8020501@ttc-cmc.net> In-Reply-To: <551460E2.8020501@ttc-cmc.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Pg-Spam-Score: -6.9 (------) 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 26/03/15 19:41, dmp wrote: > Jeremy Whiting wrote: >> Hi, >> I have been testing the current version of pgjdbc master branch. I >> added a >> test case to a branch in my repo [1] to check the behaviour when a >> multi insert >> statement adds two rows to a table. I found the return value when >> calling >> .getUpdateCount() does not equal the number of rows affected. >> >> My question is what should the return value for .getUpdateCount() >> represent. >> Is it the number of statements executed or rows put in the database ? >> >> Regards, >> Jeremy >> >> [1] >> https://github.com/whitingjr/pgjdbc/tree/updatecount-mismatches-updatecount >> > > My quick test shows it seems to be represent the the rows effected. > That is > using a single statement with multiple insert values. (3) > > INSERT INTO "public"."key_table4" ("avatar_id", "user_id", "bing_id") > VALUES > (3, 21, 20), > (5, 17, 31), > (8, 5, 7); > > If you are using single insert statements I would assume it will > always return > (1). > > According to the Java API > > Retrieves the current result as an update count; if the result is a > ResultSet object or there are no more results, -1 is returned. This > method should be called only once per result. > > Seems correct, rows effected. Using postgresql-9.4-1200.jdbc4.jar, not > current > repository though. > > danap. > > Thanks for your reply. It prompted me to do some more testing and stepping through the code. I found the return value for your example will be -1 == .getUpdateCount() whereas the int array return value for the method call .executeBatch() int[] == {3} Thanks again for helping me to understand this better. Jeremy -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc