Re: ArrayIndexOutOfBoundsException from ByteConverter.int8 when resolving generated keys

From: Vladimir Sitnikov <sitnikov(dot)vladimir(at)gmail(dot)com>
To: Erko Hansar <erko(dot)hansar(at)gmail(dot)com>
Cc: Dave Cramer <pg(at)fastcrypt(dot)com>, List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: ArrayIndexOutOfBoundsException from ByteConverter.int8 when resolving generated keys
Date: 2017-05-10 20:35:14
Message-ID: CAB=Je-HY760Y=Dhb9rFR0DJquJS0y-cnzXs89-rtd8zgrfnDZg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Here's the case:
1) Execute "insert" via non-batch multiple times. This causes pgjdbc to
server-prepare the insert and use binary transfer for the generated keys.
Note: so far so good, it is perfectly fine.
2) Execute the same SQL via batch API. Here things break. Batch-insert
wants generated keys in text format (there's QUERY_NO_BINARY_TRANSFER flag
exactly for that case), and it does ask backend to send the data in text
format. However, query metadata at pgjdbc side specify that "output columns
are in binary format", thus generated keys resultset tries to access
columns as binary and fails.

So possible workarounds are:
WA1) Add special marker (that is a comment) to batch SQL. That will make
sure batch-insert uses its own statement.
WA2) mark INT8 as text-only. It is something
like binaryTransferDisable=INT8 connection property

Vladimir

ср, 10 мая 2017 г. в 14:37, Vladimir Sitnikov <sitnikov(dot)vladimir(at)gmail(dot)com>:

> Erko>2) There was a similar problem discussed in 2012, which ended with an
> explanation:
> https://www.postgresql.org/message-id/alpine.BSO.2.00.1211081338240.29600%40leary.csoft.net
>
> I though "text-binary" flip might cause issue here. bigserial is an alias
> for int8, and int8 binary representation is 8 bytes always.
>
> Erko, if you file a pull request https://github.com/pgjdbc/pgjdbc with a
> test case, then it would get executed and we'll know if the issue is still
> there and/or which DB versions are affected.
>
> Vladimir
>

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Dave Cramer 2017-05-11 12:36:29 Re: ArrayIndexOutOfBoundsException from ByteConverter.int8 when resolving generated keys
Previous Message Vladimir Sitnikov 2017-05-10 11:37:07 Re: ArrayIndexOutOfBoundsException from ByteConverter.int8 when resolving generated keys