pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedMulti insert statement and getUpdateCount().
3+ messages / 2 participants
[nested] [flat]
* Multi insert statement and getUpdateCount().
@ 2015-03-26 16:33 Jeremy Whiting <jwhiting@redhat.com>
0 siblings, 1 reply; 3+ messages in thread
From: Jeremy Whiting @ 2015-03-26 16:33 UTC (permalink / raw)
To: pgsql-jdbc
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
--
Jeremy Whiting
Senior Software Engineer, JBoss Performance Team
Red Hat
------------------------------------------------------------
Registered Address: RED HAT UK LIMITED, 64 Baker Street, 4th Floor, Paddington. London. United Kingdom W1U 7DF
Registered in UK and Wales under Company Registration No. 3798903 Directors: Michael Cunningham (US), Charles Peters (US), Matt Parson (US) and Michael O'Neill(Ireland)
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Multi insert statement and getUpdateCount().
@ 2015-03-26 19:41 dmp <danap@ttc-cmc.net>
parent: Jeremy Whiting <jwhiting@redhat.com>
0 siblings, 1 reply; 3+ messages in thread
From: dmp @ 2015-03-26 19:41 UTC (permalink / raw)
To: Jeremy Whiting <jwhiting@redhat.com>; pgsql-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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Multi insert statement and getUpdateCount().
@ 2015-03-27 11:26 Jeremy Whiting <jwhiting@redhat.com>
parent: dmp <danap@ttc-cmc.net>
0 siblings, 0 replies; 3+ messages in thread
From: Jeremy Whiting @ 2015-03-27 11:26 UTC (permalink / raw)
To: pgsql-jdbc
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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2015-03-27 11:26 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-03-26 16:33 Multi insert statement and getUpdateCount(). Jeremy Whiting <jwhiting@redhat.com>
2015-03-26 19:41 ` dmp <danap@ttc-cmc.net>
2015-03-27 11:26 ` Jeremy Whiting <jwhiting@redhat.com>
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