Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y2McM-0000av-E2 for pgsql-jdbc@arkaria.postgresql.org; Sat, 20 Dec 2014 16:10:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y2McL-0000Wv-As for pgsql-jdbc@arkaria.postgresql.org; Sat, 20 Dec 2014 16:10:57 +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 1Y2McJ-0000Wk-09 for pgsql-jdbc@postgresql.org; Sat, 20 Dec 2014 16:10:55 +0000 Received: from mail-ie0-x236.google.com ([2607:f8b0:4001:c03::236]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Y2McB-0002WE-77 for pgsql-jdbc@postgresql.org; Sat, 20 Dec 2014 16:10:53 +0000 Received: by mail-ie0-f182.google.com with SMTP id x19so2387557ier.13 for ; Sat, 20 Dec 2014 08:10:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:mime-version:in-reply-to:content-type :content-transfer-encoding:message-id:cc:from:subject:date:to; bh=/ItgmBCax4RXqL1bLna3HJDA70D4J8CSf+z9uiib1Rc=; b=zTgCwxIIb/mHep/y+vKNrQYz9JXKBj/HPqNKMSAxlxsYMRgM9CI8VPS4zCiypDCyAU HJvSw7FNk1O19Pkb47+qBxWIhidTfgn7Yrp2spLzs/G9/W6EBAUzP9y1YlIz4Iq63nf4 D9xZdtorbcWn7QsksVVpjRs8jD9pw4HwYotL2kscMCONEIlr/U+H5lRc4eV322nozXxo 6Q4ip1DxO7ClkYtCLv2+nucP3Z6JWUR//aGh3AcowNnpr7Gy0Y2fVxKeY7T3jnw/TjSE /JAu70Ow4hB6BEmCw0uXgIaMNpJzXyNxy24n4nrlJ45ncuO3zTOkeJFo/0YnRWkoZyQP 4VsQ== X-Received: by 10.50.78.166 with SMTP id c6mr2540431igx.15.1419091844872; Sat, 20 Dec 2014 08:10:44 -0800 (PST) Received: from [192.168.1.14] (c-24-118-111-124.hsd1.mn.comcast.net. [24.118.111.124]) by mx.google.com with ESMTPSA id hi15sm2366499igb.19.2014.12.20.08.10.43 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 20 Dec 2014 08:10:43 -0800 (PST) References: Mime-Version: 1.0 (1.0) In-Reply-To: Content-Type: multipart/alternative; boundary=Apple-Mail-EC07068B-8DEA-4ED1-9009-096429652E90 Content-Transfer-Encoding: 7bit Message-Id: <028E3284-7B6B-4BC5-A6F2-757BDF02E7DF@gmail.com> Cc: Dave Cramer , List X-Mailer: iPhone Mail (11D257) From: Mo Omer Subject: Re: Postgresql 9.4 / JSONB / JDBC Date: Sat, 20 Dec 2014 10:10:43 -0600 To: Christopher BROWN X-Pg-Spam-Score: -2.7 (--) 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-EC07068B-8DEA-4ED1-9009-096429652E90 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Morning all, I've been using JSONb pretty extensively for about 2 weeks now in a pre-pro s= etup. It's advisable to not only think very hard before both of the below requests= , but to probably make them easy to disable. I recall there was a request to= do the same serialization for JSON (mayhap it was a question about JSONb, a= bout serializing on the other end, though) which was answered with a swift r= ejection. I'm pretty wary about conversions here, because if the strings I send throug= h aren't matching up with the java bytes that actually go in, that can be a m= assive PITA. However, what would be welcome is an (optional) escape method for JSON in ge= neral. After inserting ~100MM rows with COPY/JSONB, it sure would be great to optio= nally invoke a jdbc string escape method rather than substituting/escaping t= hem all myself. The existing built-in methods don't fit the requirements of C= OPY. And, COPY with JSONb has further unique requirements (I.e not escaping t= he quotes around keys and values more than language default of one slash, ye= t escaping internal chars further - or removing them) E.g. {"hello": "\tthere, \"John\""} needs to have a few extra slashes present in o= rder to be valid. Would be nice to have a solid escape method for this. Thank you for all the hard work JDBC maintainers, Mo This message was drafted on a tiny touch screen; please forgive brevity & tp= yos > On Dec 20, 2014, at 8:14 AM, Christopher BROWN wrote: >=20 > Dave, >=20 > I've only just started looking at how JSONB works in Postgresql, and am ma= inly basing ideas on what I can see here: > http://www.postgresql.org/docs/9.4/static/datatype-json.html >=20 > I suppose the basic requirement would be to be able to do stuff like this i= n JDBC: >=20 > PreparedStatement stmt =3D connection.prepareStatement("UPDATE MYTABLE SET= MYJSONCOL =3D ? WHERE MYID =3D ?"); > stmt.setObject(1, map); > stmt.setInt(2, 123); >=20 > ...as opposed to something like this (with a potentially large and variabl= e number of "?" markers): >=20 > prepareStatement("UPDATE MYTABLE SET MYJSONCOL =3D '{\"?\":?, \"?\": {\"?\= ":?}}' WHERE MYID =3D ?"); >=20 > ...or just creating a normal statement and rolling my own escaping to prev= ent SQL injection. >=20 > It would make sense to only allow keys of strings, and values of either Ma= p, Collection, Iterable, Stream, array, string, number, boolean, or null (al= though I'm a bit confused about the latter after consulting table 8-23 from t= he linked documentation above). >=20 > That would be the first requirement. >=20 > The second would be an optimisation to avoid having to convert existing da= ta structures but might need to be "a capability that you can add" rather th= an "built in". For example, I use the Jackson JSON API (there are others of= course) and I wouldn't expect it to be bundled into the driver, however it'= d be useful to pass a JSONNode object into "stmt.setObject" and have a way o= f telling the driver how to serialize it (I don't know if the getObject meth= od of a resultset can be forced to use Map or something else). Jackson has u= seful serialization methods of course, so I could just write a string suffix= ed with "::json", but I'm guessing maybe the driver provides some sort of op= timized binary representation which could be used for better performance. >=20 > Thanks, > Christopher >=20 >=20 >> On 20 December 2014 at 13:19, Dave Cramer wrote: >> Christopher, >>=20 >> No you have not missed anything, there has been nothing done with jsonb a= nd the driver. Since you are the first, perhaps you can give me your wish li= st ? >>=20 >> What would you like to see happen ? >>=20 >> Dave Cramer >>=20 >> dave.cramer(at)credativ(dot)ca >> http://www.credativ.ca >>=20 >>> On 20 December 2014 at 04:44, Christopher BROWN wrote= : >>> Hello, >>>=20 >>> I'm new to this list, and have tried searching both the mailing list arc= hives, and internet in general, for information on how to use the new JSONB d= ata type with JDBC. Found almost nothing in the mailing list archives, and i= nternet searches "helpfully" assume I've misspelled "json" and give me resul= ts that are unrelated or refer to the basic "JSON" type from older Postgresq= l versions. >>>=20 >>> How can this type be used, with simple "flat" key-value collections (map= s), with tree-like maps-of-maps, and (ideally) with JSON APIs such as Jackso= n JSON API? >>>=20 >>> Is it possible? Is it already described somewhere that I missed? >>>=20 >>> Thanks, >>> Christopher >=20 --Apple-Mail-EC07068B-8DEA-4ED1-9009-096429652E90 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Morning all,

= I've been using JSONb pretty extensively for about 2 weeks now in a pre-pro s= etup.

It's advisable to not only think very hard be= fore both of the below requests, but to probably make them easy to disable. I= recall there was a request to do the same serialization for JSON (mayhap it= was a question about JSONb, about serializing on the other end, though) whi= ch was answered with a swift rejection.

I'm pretty w= ary about conversions here, because if the strings I send through aren't mat= ching up with the java bytes that actually go in, that can be a massive PITA= .

However, what would be welcome is an (optional) e= scape method for JSON in general.

After inserting ~= 100MM rows with COPY/JSONB, it sure would be great to optionally invoke a jd= bc string escape method rather than substituting/escaping them all myself. T= he existing built-in methods don't fit the requirements of COPY. And, COPY w= ith JSONb has further unique requirements (I.e not escaping the quotes aroun= d keys and values more than language default of one slash, yet escaping inte= rnal chars further - or removing them)

E.g.

{"hello": "\tthere, \"John\""} needs to have a few extra s= lashes present in order to be valid. Would be nice to have a solid escape me= thod for this.

Thank you for all the hard work JDBC= maintainers,

Mo

This message was drafted on= a tiny touch screen; please forgive brevity & tpyos

On De= c 20, 2014, at 8:14 AM, Christopher BROWN <brown@reflexe.fr> wrote:

Dave,

I've only just started looki= ng at how JSONB works in Postgresql, and am mainly basing ideas on what I ca= n see here:

I suppose the basic requirement would b= e to be able to do stuff like this in JDBC:

Prepare= dStatement stmt =3D connection.prepareStatement("UPDATE MYTABLE SET MYJSONCO= L =3D ? WHERE MYID =3D ?");
stmt.setObject(1, map);
stmt= .setInt(2, 123);

...as opposed to something like th= is (with a potentially large and variable number of "?" markers):
=
prepareStatement("UPDATE MYTABLE SET MYJSONCOL =3D '{\"?\":?,= \"?\": {\"?\":?}}' WHERE MYID =3D ?");

...or j= ust creating a normal statement and rolling my own escaping to prevent SQL i= njection.

It would make sense to only allow keys of= strings, and values of either Map, Collection, Iterable, Stream, array, str= ing, number, boolean, or null (although I'm a bit confused about the latter a= fter consulting table 8-23 from the linked documentation above).
<= br>
That would be the first requirement.

= The second would be an optimisation to avoid having to convert existing data= structures but might need to be "a capability that you can add" rather than= "built in".  For example, I use the Jackson JSON API (there are others= of course) and I wouldn't expect it to be bundled into the driver, however i= t'd be useful to pass a JSONNode object into "stmt.setObject" and have a way= of telling the driver how to serialize it (I don't know if the getObject me= thod of a resultset can be forced to use Map or something else).  Jacks= on has useful serialization methods of course, so I could just write a strin= g suffixed with "::json", but I'm guessing maybe the driver provides some so= rt of optimized binary representation which could be used for better perform= ance.

Thanks,
<= div>
Christopher


On 20 December 2014 at 13:19, Dave Cramer <pg@= fastcrypt.com> wrote:
Christopher,

No you have not missed anything, t= here has been nothing done with jsonb and the driver. Since you are the firs= t, perhaps you can give me your wish list ?

What wo= uld you like to see happen ?

Dave Cramer

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

On 20 December 2014 at 04:44, Christopher BRO= WN <brown@reflexe.fr> wrote:
Hello,

I'm new to this list, and have tried se= arching both the mailing list archives, and internet in general, for informa= tion on how to use the new JSONB data type with JDBC.  Found almost not= hing in the mailing list archives, and internet searches "helpfully" assume I= 've misspelled "json" and give me results that are unrelated or refer to the= basic "JSON" type from older Postgresql versions.

= How can this type be used, with simple "flat" key-value collections (maps), w= ith tree-like maps-of-maps, and (ideally) with JSON APIs such as Jackson JSO= N API?

Is it possible?  Is it already describe= d somewhere that I missed?

Thanks,
= Christopher

= --Apple-Mail-EC07068B-8DEA-4ED1-9009-096429652E90--