pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: armin walland <armin@qwuh.com>
To: List <pgsql-jdbc@postgresql.org>
Subject: Re: createArrayOf("bytea", Array<byte[]>) problem
Date: Wed, 19 Feb 2014 11:39:32 +0100 (CET)
Message-ID: <88143861.14540.1392806372648.JavaMail.zimbra@qwuh.com> (raw)
In-Reply-To: <53031A0F.6040402@highgo.com.cn>
References: <52F84B99.20800@highgo.com.cn>
	<CADK3HH+N6Dcot9OT0VnwyfkxEhEZ_oNWcNoHiTOztTFWWNwPZQ@mail.gmail.com>
	<52F9CAC9.5070103@highgo.com.cn>
	<CADK3HHLK+LKtTQCrREakRWzo2Z3+HyCfufp-EzhGNgzOVy8s+A@mail.gmail.com>
	<53031A0F.6040402@highgo.com.cn>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

hi list!

i think the reason is the string representation of the 
java.sql.Array being created/sent which is (as far
as i understood it) being created in

AbstractJdbc4Connection.appendArray(StringBuffer sb, Object elements, char delim).


this function recusrively calls itself if 
o.getClass().isArray() is true, and appends 
all array values as a subarray.

for normal multidimensional arrays i think this is correct, 
but in case of a bytea[] i'm not sure. my best guess is, 
that if the Oid of the parameter is BYTEA or BYTEA_ARRAY,
the value should be hex-encoded and not treated as a nested array.

what is being sent to the server looks like this:

String representation of array: 
{{"118","-110","-61","-83","53","64","-69","-128","60","2","11","58","-18","102","-51","-120","-121","18","50","52","-22","12","110","113","67","-64","-83","-41","63","-12","49","-19"},{"63","-60","-52","-2","116","88","112","-30","-64","-39","-97","113","-13","15","-16","101","108","-115","-19","-44","28","-63","-41","-45","-45","118","-80","-37","-26","-123","-30","-13"},{"-117","91","-99","-80","-63","61","-78","66","86","-56","41","-86","54","74","-87","12","109","46","-70","49","-117","-110","50","-92","-85","-109","19","-71","84","-45","85","95"}}

but according to johto in the #postgresql irc channel, 
postgres expects an array of bytea to look like so:

String representation of array: {"\x7692c3ad3540bb803c020b3aee66cd8887123234ea0c6e7143c0add73ff431ed","\x3fc4ccfe745870e2c0d99f71f30ff0656c8dedd41cc1d7d3d376b0dbe685e2f3","\x8b5b9db0c13db24256c829aa364aa90c6d2eba318b9232a4ab9313b954d3555f"}


i have attached a small program demonstrating the problem and 
also showing, that passing an array of encoded strings works as 
expected.

my question is:

* should the jdbc driver hex-encode the bytea values inside a bytea[]
before sending them to the server
OR
* should the server "know" that the multidimensional array being 
passed is actually a bytea[] and not a byte[][].

-- 
rgds, armin walland

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

Attachments:

  pgByteaBug.tgz (application/x-compressed-tar, 7.8K) download

view thread (3+ messages)  latest in thread

Message-ID: <88143861.14540.1392806372648.JavaMail.zimbra@qwuh.com>
Permalink:  ../88143861.14540.1392806372648.JavaMail.zimbra@qwuh.com/
Also on:    postgresql.org/message-id/88143861.14540.1392806372648.JavaMail.zimbra@qwuh.com

 · 

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: armin@qwuh.com
  Subject: Re: createArrayOf("bytea", Array<byte[]>) problem
  In-Reply-To: <88143861.14540.1392806372648.JavaMail.zimbra@qwuh.com>
  References: <52F84B99.20800@highgo.com.cn> <CADK3HH+N6Dcot9OT0VnwyfkxEhEZ_oNWcNoHiTOztTFWWNwPZQ@mail.gmail.com> <52F9CAC9.5070103@highgo.com.cn> <CADK3HHLK+LKtTQCrREakRWzo2Z3+HyCfufp-EzhGNgzOVy8s+A@mail.gmail.com> <53031A0F.6040402@highgo.com.cn> <88143861.14540.1392806372648.JavaMail.zimbra@qwuh.com>

* 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