Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id DBC6B633968 for ; Thu, 22 Oct 2009 18:18:10 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 34872-08 for ; Thu, 22 Oct 2009 21:17:14 +0000 (UTC) Received: from mx2.hub.org (mx2.hub.org [200.46.204.254]) by mail.postgresql.org (Postfix) with ESMTP id F1A3563387F for ; Thu, 22 Oct 2009 18:14:13 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp160.iad.emailsrvr.com (smtp160.iad.emailsrvr.com [207.97.245.160]) by mx2.hub.org (Postfix) with ESMTP id 81F281E816EB for ; Thu, 22 Oct 2009 18:14:12 -0300 (ADT) Received: from relay16.relay.iad.mlsrvr.com (localhost [127.0.0.1]) by relay16.relay.iad.mlsrvr.com (SMTP Server) with ESMTP id 288551B4091 for ; Thu, 22 Oct 2009 17:13:01 -0400 (EDT) Received: by relay16.relay.iad.mlsrvr.com (Authenticated sender: david.wall-AT-yozons.com) with ESMTPSA id BEF701B401E for ; Thu, 22 Oct 2009 17:13:00 -0400 (EDT) Message-ID: <4AE0CADE.1000107@computer.org> Date: Thu, 22 Oct 2009 14:13:02 -0700 From: David Wall User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: pgsql-jdbc Subject: Re: JDBC with PG 8.4 bytea character escaping wire protocol References: <4ADDDFC7.3010900@computer.org> <4AE0C63D.3040303@opencloud.com> In-Reply-To: <4AE0C63D.3040303@opencloud.com> Content-Type: multipart/alternative; boundary="------------030004090006070701060908" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.274 tagged_above=-10 required=5 tests=AWL=0.324, BAYES_00=-2.599, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200910/35 X-Sequence-Number: 20037 This is a multi-part message in MIME format. --------------030004090006070701060908 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit > Does the JDBC 4 driver for PG 8.4 escape each character of the bytea > type, or does it use a binary protocol? > > When sending parameter data to the server, it uses the binary format. > > When receiving results from the server, it uses the text format. Thanks, Oliver. Well, I hadn't even thought it could be both. There was confusion in the other replies because they were looking at how the data moves from my code into the driver, but not how the driver communicates with the backend. It was clear I could store binary data as I was doing that just fine, but the PG docs made it sound like much of my binary data would end up expanding because more than half of the range an octet may have requires escaping per http://www.postgresql.org/docs/8.4/static/datatype-binary.html: *Table 8-7. bytea Literal Escaped Octets* Decimal Octet Value Description Escaped Input Representation Example Output Representation 0 zero octet E'\\000' SELECT E'\\000'::bytea; \000 39 single quote '''' or E'\\047' SELECT E'\''::bytea; ' 92 backslash E'\\\\' or E'\\134' SELECT E'\\\\'::bytea; \\ 0 to 31 and 127 to 255 "non-printable" octets E'\\/xxx'/ (octal value) SELECT E'\\001'::bytea; \001 I am thinking this should not be a real issue for me since I will be using LOs for by big objects and BYTEAs for the smaller objects. Thanks again, David --------------030004090006070701060908 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
Does the JDBC 4 driver for PG 8.4 escape each character of the bytea type, or does it use a binary protocol?

When sending parameter data to the server, it uses the binary format.

When receiving results from the server, it uses the text format.

Thanks, Oliver.  Well, I hadn't even thought it could be both. <smile> 

There was confusion in the other replies because they were looking at how the data moves from my code into the driver, but not how the driver communicates with the backend.  It was clear I could store binary data as I was doing that just fine, but the PG docs made it sound like much of my binary data would end up expanding because more than half of the range an octet may have requires escaping per http://www.postgresql.org/docs/8.4/static/datatype-binary.html:

Table 8-7. bytea Literal Escaped Octets

Decimal Octet Value Description Escaped Input Representation Example Output Representation
0 zero octet E'\\000' SELECT E'\\000'::bytea; \000
39 single quote '''' or E'\\047' SELECT E'\''::bytea; '
92 backslash E'\\\\' or E'\\134' SELECT E'\\\\'::bytea; \\
0 to 31 and 127 to 255 "non-printable" octets E'\\xxx' (octal value) SELECT E'\\001'::bytea; \001

I am thinking this should not be a real issue for me since I will be using LOs for by big objects and BYTEAs for the smaller objects.

Thanks again,
David
--------------030004090006070701060908--