pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: dmp <danap@ttc-cmc.net>
To: Jeremy Whiting <jwhiting@redhat.com>
To: PostgreSQL JDBC <pgsql-jdbc@postgresql.org>
Subject: Re: Multi insert statement and getUpdateCount().
Date: Thu, 26 Mar 2015 13:41:22 -0600
Message-ID: <551460E2.8020501@ttc-cmc.net> (raw)
In-Reply-To: <551434D9.6040906@redhat.com>
References: <551434D9.6040906@redhat.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

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.


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (3+ messages)  latest in thread

Message-ID: <551460E2.8020501@ttc-cmc.net>
Permalink:  ../551460E2.8020501@ttc-cmc.net/
Also on:    postgresql.org/message-id/551460E2.8020501@ttc-cmc.net

 · 

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-jdbc@postgresql.org
  Cc: danap@ttc-cmc.net, jwhiting@redhat.com
  Subject: Re: Multi insert statement and getUpdateCount().
  In-Reply-To: <551460E2.8020501@ttc-cmc.net>
  References: <551434D9.6040906@redhat.com> <551460E2.8020501@ttc-cmc.net>

* 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