Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZCZBU-000557-Om for pgsql-jdbc@arkaria.postgresql.org; Tue, 07 Jul 2015 20:09:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZCZBU-0005St-7u for pgsql-jdbc@arkaria.postgresql.org; Tue, 07 Jul 2015 20:09:40 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZCZAn-0004qd-4s for pgsql-jdbc@postgresql.org; Tue, 07 Jul 2015 20:08:57 +0000 Received: from st11p05im-asmtp002.me.com ([17.172.109.150]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZCZAk-0002gx-9Z for pgsql-jdbc@postgresql.org; Tue, 07 Jul 2015 20:08:55 +0000 Received: from [192.168.100.2] (ip68-2-54-213.ph.ph.cox.net [68.2.54.213]) by st11p05im-asmtp002.me.com (Oracle Communications Messaging Server 7.0.5.35.0 64bit (built Mar 31 2015)) with ESMTPSA id <0NR4001PGVYNCL50@st11p05im-asmtp002.me.com> for pgsql-jdbc@postgresql.org; Tue, 07 Jul 2015 20:08:50 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.14.151,1.0.33,0.0.0000 definitions=2015-07-07_07:2015-07-07,2015-07-07,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=1 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1412110000 definitions=main-1507070304 Content-type: multipart/alternative; boundary="Apple-Mail=_551647FC-3880-4D18-83BD-1AA66D6DBDF0" MIME-version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) Subject: Re: PostgreSQL gaps wrt to java, and jdbc From: Kevin Wooten In-reply-to: <559C3053.2060106@iki.fi> Date: Tue, 07 Jul 2015 13:08:47 -0700 Cc: Dave Cramer , List Message-id: <5973AC3D-69C0-4CE8-A5FD-D3F045480543@me.com> References: <80FEC5E5-DD36-46F4-A510-31E08415FBB1@me.com> <559C2CA8.6000200@iki.fi> <559C3053.2060106@iki.fi> To: hlinnaka@iki.fi X-Mailer: Apple Mail (2.2070.6) X-Pg-Spam-Score: -3.4 (---) 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 --Apple-Mail=_551647FC-3880-4D18-83BD-1AA66D6DBDF0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jul 7, 2015, at 1:02 PM, Heikki Linnakangas = wrote: >=20 > On 07/07/2015 10:51 PM, Dave Cramer wrote: >> On 7 July 2015 at 15:46, Heikki Linnakangas wrote: >>=20 >>> On 07/07/2015 09:31 PM, Kevin Wooten wrote: >>>=20 >>>> =3D=3D Binary type coercion =3D=3D >>>> The biggest impediment I=E2=80=99ve run into is the fact that PG = will not >>>> attempt coercion on binary types. If you specify a binary type in = the >>>> protocol, that=E2=80=99s the final word. A better system would be = to have PG >>>> perform the same coercion it does for text types and then send the >>>> results back with coerced types, in binary; finally falling back to >>>> text when binary cannot be produced. This would solve almost every >>>> issue we have had to work around in the =E2=80=9Cng=E2=80=9D = driver. >>>>=20 >>>=20 >>> Can you elaborate? I'm confused, because the server can produce = binary >>> output for any datatype that has binary output functions. That = covers all >>> built-in datatypes and all extension datatypes people use in = practice. >>>=20 >>> What I've imagined to be a problem, though, is that you have to = either >>> understand the binary representation of all datatypes in the client, = or you >>> have to request binary for only those datatypes you can handle. And = to know >>> which datatype a result set's column has, you have to Describe it = before >>> fetching the results, which adds an extra round-trip. So it would be = handy >>> if the driver could provide the server a list of datatypes that = should be >>> sent as binary, as a one-time operation at the beginning of the = session for >>> example, rather than indicating for each column in each query = separately. >>>=20 >> Is there a way to get json and or xml out as binary ? >=20 > Well, as far as the protocol is considered, yes. However, the "binary = representation" of json and xml datatypes is not too exciting; here's = the binary send function for json for example: >=20 > /* > * Binary send. > */ > Datum > json_send(PG_FUNCTION_ARGS) > { > text *t =3D PG_GETARG_TEXT_PP(0); > StringInfoData buf; >=20 > pq_begintypsend(&buf); > pq_sendtext(&buf, VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t)); > PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); > } >=20 > I.e. it just sends the string with a bytea header. There is no benefit = to using that instead of the regular text representation. That dummy = representation is used just so that e.g. binary-format pg_dump works. >=20 > - Heikki This confused me when we went to implement this as a binary type. = Isn=E2=80=99t it stored in a binary format? Or is that just an = intermediate format that=E2=80=99s cached around inside the server? --Apple-Mail=_551647FC-3880-4D18-83BD-1AA66D6DBDF0 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8
On Jul 7, 2015, at 1:02 PM, Heikki Linnakangas <hlinnaka@iki.fi> = wrote:

On 07/07/2015 10:51 PM, Dave Cramer = wrote:
On 7 July 2015 at 15:46, Heikki Linnakangas <hlinnaka@iki.fi> = wrote:

On 07/07/2015 09:31 PM, Kevin Wooten wrote:

=3D=3D Binary type = coercion =3D=3D
The biggest impediment I=E2=80=99ve run = into is the fact that PG will not
attempt coercion on = binary types. If you specify a binary type in the
protocol, = that=E2=80=99s the final word. A better system would be to have PG
perform the same coercion it does for text types and then = send the
results back with coerced types, in binary; = finally falling back to
text when binary cannot be = produced. This would solve almost every
issue we have had = to work around in the =E2=80=9Cng=E2=80=9D driver.


Can you elaborate? I'm confused, = because the server can produce binary
output for any = datatype that has binary output functions. That covers all
built-in datatypes and all extension datatypes people use in = practice.

What I've imagined to be a = problem, though, is that you have to either
understand the = binary representation of all datatypes in the client, or you
have to request binary for only those datatypes you can = handle. And to know
which datatype a result set's column = has, you have to Describe it before
fetching the results, = which adds an extra round-trip. So it would be handy
if = the driver could provide the server a list of datatypes that should = be
sent as binary, as a one-time operation at the = beginning of the session for
example, rather than = indicating for each column in each query separately.

Is there a way to get json and or xml out as = binary ?

Well, as far as the = protocol is considered, yes. However, the "binary representation" of = json and xml datatypes is not too exciting; here's the binary send = function for json for example:

/*
* Binary send.
*/
Datum
json_send(PG_FUNCTION_ARGS)
{
       text =       *t =3D = PG_GETARG_TEXT_PP(0);
       StringInfoData = buf;

       pq_begintypsend(&= buf);
       pq_sendtext(&buf,= VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t));
       PG_RETURN_BYTEA_P(pq_= endtypsend(&buf));
}

I.e. it just sends the string with a bytea = header. There is no benefit to using that instead of the regular text = representation. That dummy representation is used just so that e.g. = binary-format pg_dump works.

- = Heikki

This confused me when we went to implement this as a = binary type.  Isn=E2=80=99t it stored in a binary format? Or is = that just an intermediate format that=E2=80=99s cached around inside the = server?


= --Apple-Mail=_551647FC-3880-4D18-83BD-1AA66D6DBDF0--