Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y6SeW-0005Zg-N6 for pgsql-jdbc@arkaria.postgresql.org; Wed, 31 Dec 2014 23:26:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y6SeW-0004HC-6Z for pgsql-jdbc@arkaria.postgresql.org; Wed, 31 Dec 2014 23:26:08 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y6SeU-0004EQ-IO for pgsql-jdbc@postgresql.org; Wed, 31 Dec 2014 23:26:06 +0000 Received: from mail5.spectralogic.com ([192.30.190.19]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y6SeQ-0002Sz-LL for pgsql-jdbc@postgresql.org; Wed, 31 Dec 2014 23:26:04 +0000 From: Hans Klett To: Christopher BROWN CC: List Subject: Re: Postgresql 9.4 / JSONB / JDBC Thread-Topic: [JDBC] Postgresql 9.4 / JSONB / JDBC Thread-Index: AQHQHDm6yb9SyAjHfE6Uwlbo9MT88pym26mAgAAaTgCAA5ZigIAALxmA//+qaAA= Date: Wed, 31 Dec 2014 23:11:49 +0000 Message-ID: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Microsoft-MacOutlook/14.3.5.130515 x-originating-ip: [192.168.200.15] Content-Type: multipart/alternative; boundary="_000_D0C9BC261AA0hanskspectralogiccom_" MIME-Version: 1.0 X-Pg-Spam-Score: -1.9 (-) 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 --_000_D0C9BC261AA0hanskspectralogiccom_ Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Correct me if I=92m wrong, but streaming a parameter value is impossible un= less you know its size beforehand: http://www.postgresql.org/docs/9.4/static/protocol-message-formats.html Under =93Bind=94, which does prepared statement parameter binding: Next, the following pair of fields appear for each parameter: Int32 The length of the parameter value, in bytes (this count does not include it= self). Can be zero. As a special case, -1 indicates a NULL parameter value.= No value bytes follow in the NULL case. Byten The value of the parameter, in the format indicated by the associated forma= t code. n is the above length. I don=92t know how you figure out the payload size without encoding the who= le thing. Note that array parameters are serialized into a string before be= ing sent over the wire. Thanks, - Hans From: Christopher BROWN > Date: Wednesday, December 31, 2014 at 2:18 PM To: Mikko Tiihonen > Cc: Dave Cramer >, List > Subject: Re: [JDBC] Postgresql 9.4 / JSONB / JDBC Unless there is a requirement to devise a new solution, in the absence of a= ny formal standard, I am aware of two similar specifications: - http://bsonspec.org/ (for MongoDB) - http://wiki.fasterxml.com/SmileFormatSpec (for Jackson JSON) I've used and continue to use the latter and it works well for me. Does the PostgreSQL client/server protocol allow for protocol upgrades, in = a similar way to what HTTP defines for SPDY or websockets? That might addr= ess Mikko's remarks about backward compatibility. How is "hstore" data transmitted? Is it optimized and could JSONB "piggyba= ck" it? -- Christopher On 31 December 2014 at 19:29, Mikko Tiihonen > wrote: Last time I checked (few months ago), the postgresql jsonb binary format wa= s just a extra 4 byte version header followed by text json data. So basical= ly the binary jsonb format was slower than text format. And since there is = no official plan on how to modify the binary formats without breaking backw= ards compatibility it most likely will stay that way. Having a proper binary encoding for jsonb would speed up parsing on both se= rver and client side. -Mikko ________________________________ From:pgsql-jdbc-owner@postgresql.org >= on behalf of Dave Cramer > Sent: 29 December 2014 13:42 To: Christopher BROWN Cc: List Subject: Re: [JDBC] Postgresql 9.4 / JSONB / JDBC Yes, we can pull the data from the server in binary. After that though we h= ave to convert it to text Dave Cramer dave.cramer(at)credativ(dot)ca http://www.credativ.ca On 29 December 2014 at 05:08, Christopher BROWN > wrote: Hello, Regarding my previous messages on this subject (JSONB support in the Postgr= esql JDBC driver), one assumption I'm making is that the driver might be ab= le to stream the JSON data more efficiently that just throwing a chunk of t= ext onto the wire... as text isn't the most efficient way of encoding numbe= rs, booleans, and nulls. How does the native network protocol of Postgresql actually transfer such d= ata? Is there an opportunity for sending the data efficiently? Personally= for some of my applications, I'm able to use Jackson's "Smile" binary JSON= format, although I doubt that the Postgresql server would understand it or= want to implement it (I don't know if it could be considered a standard, e= ven if it's specified -- http://wiki.fasterxml.com/SmileFormatSpec). -- Christopher On 20 December 2014 at 10:44, Christopher BROWN > wrote: Hello, I'm new to this list, and have tried searching both the mailing list archiv= es, and internet in general, for information on how to use the new JSONB da= ta type with JDBC. Found almost nothing in the mailing list archives, and = internet searches "helpfully" assume I've misspelled "json" and give me res= ults that are unrelated or refer to the basic "JSON" type from older Postgr= esql versions. How can this type be used, with simple "flat" key-value collections (maps),= with tree-like maps-of-maps, and (ideally) with JSON APIs such as Jackson = JSON API? Is it possible? Is it already described somewhere that I missed? Thanks, Christopher --_000_D0C9BC261AA0hanskspectralogiccom_ Content-Type: text/html; charset="Windows-1252" Content-ID: Content-Transfer-Encoding: quoted-printable
Correct me if I=92m wrong, but streaming a parameter value is impossible un= less you know its size beforehand:

Under =93Bind=94, which does prepared statement parameter binding:

Next, the following pair of fields appear for each parameter:

Int3= 2

The len= gth of the parameter value, in bytes (this count does not include itself). = Can be zero. As a special case, -1 indicates a NULL parameter value. No val= ue bytes follow in the NULL case.

Byten

The val= ue of the parameter, in the format indicated by the associated format code.=  n is the above length.

I don=92t know how you figure out the payload size without encoding th= e whole thing. Note that array parameters are serialized into a string befo= re being sent over the wire.

Thanks,
- Hans

From: Christopher BROWN <brown@reflexe.fr>
Date: Wednesday, December 31, 2014 = at 2:18 PM
To: Mikko Tiihonen <Mikko.Tiihonen@nitorcreations.com<= /a>>
Cc: Dave Cramer <
pg@fastcrypt.com>, List <pgsql-jdbc@postgresql.org>
Subject: Re: [JDBC] Postgresql 9.4 = / JSONB / JDBC

Unless there is a requirement to devise a new solution, in= the absence of any formal standard, I am aware of two similar specificatio= ns:

- http://bsonspec.org/ (for Mongo= DB)

I've used and continue to use the latter and it works well for me.

Does the PostgreSQL client/server protocol allow for protocol upgrades= , in a similar way to what HTTP defines for SPDY or websockets?  That = might address Mikko's remarks about backward compatibility.

How is "hstore" data transmitted?  Is it optimized and = could JSONB "piggyback" it?

--
Christopher


On 31 December 2014 at 19:29, Mikko Tiihonen <= Mikko.Tiihonen@nitorcreations.com> wrote:

Last time I checked (few months ago), the postgresql jsonb binary format= was just a extra 4 byte version header followed by text json data. So basi= cally the binary jsonb format was slower than text format. And since there = is no official plan on how to modify the binary formats without breaking backwards compatibility it most likely= will stay that way.


Having a proper binary encoding for jsonb would speed up parsing on both= server and client side.


-Mikko


From:pgsql-jdbc-owner@postgresql.org <pgsql-jdbc-owner= @postgresql.org> on behalf of Dave Cramer <pg@fastcrypt.com>
Sent: 29 December 2014 13:42
To: Christopher BROWN
Cc: List
Subject: Re: [JDBC] Postgresql 9.4 / JSONB / JDBC
 
Yes, we can pull the data from the server in binary. After= that though we have to convert it to text

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca=

On 29 December 2014 at 05:08, Christopher BROWN = <brown@reflexe.fr<= /a>> wrote:
Hello,

Regarding my previous messages on this subject (JSONB support in the P= ostgresql JDBC driver), one assumption I'm making is that the driver might = be able to stream the JSON data more efficiently that just throwing a chunk= of text onto the wire... as text isn't the most efficient way of encoding numbers, booleans, and nulls.



--_000_D0C9BC261AA0hanskspectralogiccom_--