Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Z9gXn-0008HV-9Y for pgsql-jdbc@arkaria.postgresql.org; Mon, 29 Jun 2015 21:24:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Z9gXm-0004xn-GG for pgsql-jdbc@arkaria.postgresql.org; Mon, 29 Jun 2015 21:24:46 +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 1Z9gXl-0004xM-28 for pgsql-jdbc@postgresql.org; Mon, 29 Jun 2015 21:24:45 +0000 Received: from mail-pa0-x230.google.com ([2607:f8b0:400e:c03::230]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1Z9gXh-0006dV-I5 for pgsql-jdbc@postgresql.org; Mon, 29 Jun 2015 21:24:43 +0000 Received: by paceq1 with SMTP id eq1so110494293pac.3 for ; Mon, 29 Jun 2015 14:24:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=pml0cc+Y4r+6D7Ip3S999aV0/MN1LIvP3+t3s/arBj4=; b=H7slbpzwdALtg2ltZQrcyz13aWBa03ChzkzWCukwYfpCwKGG3Q8DNHBwyRIGZklmMz MUMhYROZpXOtoh5bKUimg1vKUGkXJt+y6tU83SrzXpyA21mylL0hcRnZjoqpq4rCCph0 HqVP0Wbm74MbU2Wd18EE75slqGSq15+EW7WOdENWgCtPTNPGJj7kyUlIem2T8VgG3tbh +wwVdu5RGyma8YvgtpwKWe9e1Dgm7qdd0SPaRzpaR3NJaq2HV9BqFnnEqb/4rdSL+R+P lBgujFF4jBRLsGC++7QJKsrkSL/eD5aO86S3VIHUBno1uIU+rw/P0zYvZUaVrm3j2AJj qYtg== X-Received: by 10.66.141.137 with SMTP id ro9mr35392845pab.152.1435613080399; Mon, 29 Jun 2015 14:24:40 -0700 (PDT) Received: from [10.10.21.80] (otra.opentable.com. [199.16.144.7]) by mx.google.com with ESMTPSA id qc5sm14533622pab.14.2015.06.29.14.24.38 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 29 Jun 2015 14:24:39 -0700 (PDT) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Subject: Re: SQLJSON From: Steven Schlansker In-Reply-To: Date: Mon, 29 Jun 2015 14:24:37 -0700 Cc: Markus KARG , List Content-Transfer-Encoding: quoted-printable Message-Id: <427C3729-5331-4C71-8951-CA19631B8115@gmail.com> References: <558ED5A6.4070500@8Kdata.com> <002701d0b104$114cdd60$33e69820$@eu> <000601d0b125$17d3fee0$477bfca0$@eu> <558F22BE.5050508@8Kdata.com> <558F377B.7040606@8Kdata.com> <558FC12E.8010107@8Kdata.com> <000301d0b187$aeb51a30$0c1f4e90$@eu> <558FC4E1.7020005@8Kdata.com> <001301d0b1b4$7f0862b0$7d192810$@eu> <5590458C.3040805@8Kdata.com> <002901d0b288$52a8e080$f7faa180$@eu> <5591960B.7070406@8Kdata.com> <008d01d0b2a9$46248500$d26d8f00$@eu> To: Dave Cramer X-Mailer: Apple Mail (2.1878.6) X-Pg-Spam-Score: -1.2 (-) 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 I apologize in advance if I've missed something, the volume of emails in th= is thread is getting ... a bit overwhelming. My understanding of the situation is: * Without JDBC5, we cannot expect our solution to be portable * Without PG backend / protocol improvements, we cannot have our solution b= e faster or more efficient * Without bloating the driver (and locking ourselves in to not receiving up= stream bug fixes without re-rolling the driver) or requiring external depen= dencies, we cannot have a nicer API to return JSON (and even if we do, see = #1) Particularly in the case of using SQLJSON as a cursor-like construct to par= tially retrieve JSON values (did I understand that correctly?), it feels li= ke we are rushing to implement something that cannot possibly be implemente= d efficiently today, and if it does eventually get server / protocol suppor= t, our API is just as likely to be a total mismatch as it is to mesh well. I would also like to point out that adding new methods to PGConnection is g= reat, but as soon as you introduce a connection pool or other type of facad= e (which is, to my understanding, by far the common case) using any non-int= erface methods becomes extremely confusing. At the very best you have to d= eal with "unwrapping" any potentially wrapped objects (Connection, ResultSe= t, Statement, etc) and worse you may find your pool does not bother to impl= ement the Wrapper interface since it did not even exist until Java 6 and th= ese tools move extremely slowly. And it all breaks when you switch connect= ion pools and they have a different way of doing the wrapping... I wonder if it would not be more prudent to wait until JDBC has an API to a= rgue about, or Postgres protocol supports at least one of the proposed feat= ures, rather than rushing to bake our own at the that we know has very litt= le improvement over what you can do out of the box today. We are trying to= build a feature from the middle out, rather than letting it be driven eith= er top-down or bottom-up. I hope I haven't misunderstood anything here, I'm just having a very hard t= ime figuring out the actual use case we are trying to solve from the large = mash of emails. To be clear, I say this as someone who has used the Postgr= es JSON support relatively extensively, and would love to see improvements.= Maybe one of the advocates here could provide some "pseudo-code" use case= s? A "story" for the proposal, if you will? Sell me, make me wish for thi= s feature :) To me the litmus test would be how much you can improve over the naive "end= user ties Jackson and JDBC together" approach, namely things such as rs =3D ps.execute("SELECT json_field FROM table WHERE condition =3D 42"); domainObject =3D mapper.readValue(rs.getBytes("json_field"), DomainObject.c= lass); either in terms of * Code cleanliness that is more fundamental than a syntactic sugar helper m= ethod - For example a getJsonValue(rs, "json_field", DomainObject.class) shortha= nd * Performance - Processing time - Memory usage * Versatility - Not sure what people are missing here? Except the SQLJSON cursor which = we cannot possibly implement efficiently today Anyway, I'm really not trying to be a wet blanket here, I just want to make= sure we all have a clear idea of what problems we are and are not solving = by this proposed feature. Don't want to stretch our already limited pg-jdb= c development resource even more thinly! On Jun 29, 2015, at 1:58 PM, Dave Cramer wrote: > On 29 June 2015 at 16:22, Markus KARG wrote: > Dave, >=20 >=20=20 >=20 > I understand that people expect that getObject does something reasonable = - but the case why this does not happen is because PostgreSQL does not prov= ide something reasonable AFAIK, or is there JSON support in the protocol (I= might have missed that, actually, then please just tell me)? >=20 >=20 >=20 > Well things in PostgreSQL move at rather a glacial pace as far as featur= es go. The emphasis is on reliability. If you think this mailing list is co= ntentious you might want to have a look at hackers. To answer your question= though there is no special backend support for JSON, or any other streamin= g. Yes this is a performance drawback, but it is what it is.=20=20 >=20=20 >=20 > But I need to tell you that you have to deal with the risk that if JDBC 5= comes up with the definition "getObject has to return FancyJsonType" you'l= l face a backwards compatibility problem when you decided for pretty anythi= ng to return but not "FancyJsonType", whether the type you've choosen looke= d obvious to the common user, to almost any user or to nobody at all. Anywa= ys, you're the boss, and I trust in you to do the right choice. :-) >=20 >=20 > Doing nothing is surely the wrong choice. The question is what to do. I d= on't pretend to know the right answer here.However in the absence of the sp= ec, I'm sure whatever we do will be a compromise. >=20 >=20=20 >=20 > Regarding your metaphor, please in turn understand thar some guys in this= form, like Vladimir and me, are professional combustion engine engineers i= n our main job. Our whole life is dedicated to the difference between a van= illa BMW 318 into an M3. I hope there is place for such engineers in your t= eam, too, and it is _not_really_ your attitude that you are happy once the = weels don't fall away once you start the motor. We do not do it for thank o= r cheer, we simply do it because it is the attitude of our main jobs. We ca= nnot forget our knowledge about compression and consumption just because 99= % of the users don't care for. And part of this knowledge is thinking of ef= ficiency and safety and cost of production and unassembly for recycling, an= d usefulness and maintainability and testability of the car, too, even if n= o user _ever_ would think about when sitting is his ride. If our demands on= the professionality and performance of the end product is not what you lik= e to achieve and you like to simply replace the pipe with a chromed one, th= en please let us know. Otherwise our PRs will one day produce a stack overf= low on GitHub, which nobody wants. ;-) >=20 >=20 > As I said in my earlier email I am grateful for your contributions and I = would love them to continue, but we need to keep the majority of the users = in mind. We also need to make sure in our quest for performance that we don= 't break anything. >=20 > Regards, >=20 > Dave=20 >=20 >=20=20 >=20 > Have fun >=20 > -Markus >=20 >=20=20 >=20 >=20=20 >=20 > From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql= .org] On Behalf Of Dave Cramer > Sent: Montag, 29. Juni 2015 21:23 > To: =C1lvaro Hern=E1ndez Tortosa > Cc: List > Subject: Re: [JDBC] SQLJSON >=20 >=20=20 >=20 > Markus, >=20 >=20=20 >=20 > I really value your recent input to the driver and would like it to conti= nue but we need to keep things in perspective. The mere fact that you are e= ngaging in discussion on this list puts you in the 99.99999th (keep going w= ith 9's if you like) percentile of users. Most and I mean the rest of the p= eople in that population just expect the driver to do something reasonable.= They don't provide JSON parsers or even know there is a difference. When t= hey do getObject and that object is a json value they expect something magi= cal to happen. We return an object they can use. >=20 >=20=20 >=20 > The other less than exciting fact about the driver is that it is not the = central feature of PostgreSQL. Allow me a metaphor if you will. I like cars= so I'll chose to use a driveshaft. It connects the engine to the wheels. T= here is nothing new about driveshafts, although recently they have been mad= e out of carbon fibre, but essentially they are tubes which connect the cra= nkshaft to the wheels. To continue the metaphor, when the driver applies th= e gas pedal they expect the car to move. If the driveshaft breaks then this= doesn't happen. Our job is to make sure the driveshaft continues to connec= t the engine to the wheels. If we can make it out of carbon fibre so much t= he better, but it is a particularly thankless job. >=20 >=20=20 >=20 >=20=20 >=20 > Kind Regards, >=20 >=20 >=20 > Dave Cramer >=20 > dave.cramer(at)credativ(dot)ca > http://www.credativ.ca >=20 >=20=20 >=20 > On 29 June 2015 at 15:01, =C1lvaro Hern=E1ndez Tortosa w= rote: >=20 >=20 > Markus: >=20 > On 29/06/15 18:26, Markus KARG wrote: >=20 > Unfortunately, yes, it is weird to ask, as what you do actually is workin= g already once you accept the technical reality that an application either = has to use JSON SQL functions OR provide an implementation of the JSONP API= to be able to process JsonObject. >=20 >=20 > It was rhetorical. Precisely I'm saying let's include an implementati= on so that you could process a JsonValue. Of course.=20 >=20 >=20 >=20 > I actually cannot see what is so specific to PostgreSQL that pgjdbc has t= o support a use case that no other driver supports. >=20 >=20 > Maybe that PostgreSQL has JSON, really good one, while others don't? = Or let's ruin all the work done into JSON just because you fear of an absol= utely unrealistic class path? Really? Please.... >=20 >=20 >=20 >=20=20 >=20 > The argument against it is that it provides classpath clashes once pgjdbc= is used in a Java EE environment, and that our solution might be incompati= ble with JDBC 5, and that our solution imposes work and complexity on the p= gjdbc contributors just for the sake to make you happy, without providing y= ou any measurable benefit. >=20 >=20 > Markus, when you say "to make you happy".... please take back your w= ords and stick to rational arguments. If you cannot, please abandon this ot= herwise respectful and enriching debate. >=20 > I'm speaking for all the users, all of them that want to use 9.4's be= st thing (with logical decoding permission, of course). >=20 > Yet you only want to stop everything speaking of a class path that ve= ry likely no one will ever experience, or some fears about JDBC5 which migh= t be light years ahead. We will worry about JDBC5 then, but now we need to = help our users, not help them (with your help) to go to MongoDB. >=20 >=20 >=20 >=20 > =C1lvaro >=20 >=20 >=20 >=20 > --=20 > =C1lvaro Hern=E1ndez Tortosa >=20=20 >=20=20 > ----------- > 8Kdata >=20=20 >=20 >=20 >=20 >=20 >=20=20 >=20 > -Markus >=20 >=20=20 >=20 > From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql= .org] On Behalf Of =C1lvaro Hern=E1ndez Tortosa > Sent: Sonntag, 28. Juni 2015 21:06 > To: pgsql-jdbc@postgresql.org > Subject: Re: [JDBC] SQLJSON >=20 >=20=20 >=20 >=20=20 >=20 > On 28/06/15 17:09, Markus KARG wrote: >=20 > If your application does not want to deal with JSON data then don't reque= st it from the database, but use http://www.postgresql.org/docs/9.4/static/= functions-json.html in your SELECT statement. Performing a JSON extraction = function natively on the server and simply use the existing data types in y= our application not only reliefs us from dealing with JSON in the driver, b= ut also will work magnitudes faster particularly on congested networks. Tha= t does work by default already in the existing driver. What you ask for doe= s not provide any benefit to the user from my view, or I still do not under= stand you exact scenario. >=20 >=20 > Markus, here you are trying to tell users what to do. I prefer to giv= e them freedom, works best. >=20 > All I'm saying is: >=20 > - Give users an API to get a javax.json.JsonValue out of a PostgreSQL col= umn which is of type json, jsonb or the result of an expression which evalu= ates to any of those. >=20 > - Embed a JSON parser in the driver (like the RI implementation, which ad= ds only 64Kb) so that users don't need to load any other code, unless they = want to override the default JSON parser. >=20 > From there, I don't care whether the user uses JSON functions at the = server or the JSON API. What I want is that it works by default and that yo= u can query JSON. Is this that weird to ask? >=20 > I'm sorry, I fail to understand your solution to the problem. Would y= ou please mind elaborating on the drawbacks of my proposal? I stated in pre= vious emails the drawbacks I see on not doing it, but I still fail to see a= n argument against this. >=20 > Thanks, >=20 > =C1lvaro >=20 >=20 >=20 > --=20 > =C1lvaro Hern=E1ndez Tortosa >=20=20 >=20=20 > ----------- > 8Kdata >=20=20 >=20=20 >=20 >=20=20 >=20 > From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc-owner@postgresql= .org] On Behalf Of =C1lvaro Hern=E1ndez Tortosa > Sent: Sonntag, 28. Juni 2015 11:57 > To: pgsql-jdbc@postgresql.org > Subject: Re: [JDBC] SQLJSON >=20 >=20=20 >=20 >=20=20 >=20 > On 28/06/15 11:49, Markus KARG wrote: >=20 > You miss one essential point against bundling: An application author who = wants to process JsonObject must have that class on his classpath, even if = he does not use JDBC at all. This essential is HIS problem as HE wants to p= rocess it. So where does he get that class from other than putting any JSR = 253 implementation in his classpath? Again, it is simply not pgjdbc's probl= em as in that scenario no JDBC is used at all. >=20 > I don't agree, it's not a must. I may want to extract JSON data from = the database and then manipulate it as non-JSON data. It all depends on you= r domain Objects. >=20 > I already stated how bad for the user is not to have a driver that wo= rks by default. It may be as hard as adding a 64Kb to the driver. I don't u= nderstand how is this a problem, vs. the problem it creates for the user. >=20 > Regards, >=20 > =C1lvaro >=20 >=20 >=20 >=20 > --=20 > =C1lvaro Hern=E1ndez Tortosa >=20=20 >=20=20 > ----------- > 8Kdata >=20=20 >=20 >=20 >=20 >=20 >=20=20 >=20 > From: =C1lvaro Hern=E1ndez Tortosa [mailto:aht@8Kdata.com]=20 > Sent: Sonntag, 28. Juni 2015 11:41 > To: Christopher BROWN > Cc: Sehrope Sarkuni; Markus KARG; Dave Cramer; List > Subject: Re: [JDBC] SQLJSON >=20 >=20=20 >=20 >=20=20 >=20 > On 28/06/15 09:34, Christopher BROWN wrote: >=20 > Hello, >=20 >=20=20 >=20 > Quick contribution, I'm not answering in-line because there are already t= oo many in-line answers and it's getting unreadable. >=20 > =95 In my own applications, I use Jackson, but it's many up of different= ".jar" files and has therefore no definitive form (you can concoct lots of= combinations). It's also quite heavy in terms of footprint, and embedding= it makes no sense, because you'd have to keep updating the driver to keep = up to date with Jackson. Finally, it doesn't actually implement JSR353 (alt= hough it would be possible to create a thin wrapper), out-of-the-box (via a= compatibility API) it can read JSR-353 but it basically rebuilds a Jackson= representation out of a "standard" representation. I might choose Jackson= , but I wouldn't want to impose it or require that it be bundled with the d= river (indeed, that would cause me classloader issues as I often update to = the latest version of Jackson). > Although I mentioned Jackson as a good candidate for a default implem= entation, you are right it does not implement JSR353 directly (although wra= ppers already exist, like https://github.com/pgelinas/jackson-javax-json). = But it does not need to be the default choice. I did a quick test and wrapp= ing Jackson with jaackson-javax-json and the set of dependencies to make it= work would add 1102Kb to the Jar file. Not much IMHO, although bigger than= current driver size. I would not be scared however to see a 2Mb jdbc jar f= ile. >=20 > However, the Reference Implementation (https://jsonp.java.net/) is pr= obably good enough and only adds 64Kb to the Jar file. The JSR353 is just a= nother 32Kb, so in total 96Kb would be added if using the RI rather than Ja= ckson. I don't consider this offensive. >=20 > In summary: why not bundle then the RI? Works out of the box and does= not conflict with Jackson. Want to use Jackson? Go for it. The rest of the= world would have something running out-of-the-box. >=20 >=20 >=20 > =95 You can compile the driver against the JSONP API without embedding e= ither the interfaces or an implementation. It's therefore an optional feat= ure for those that require it, and it's not rocket science to add the neces= sary APIs to the classpath. > =95 I disagree that bundling interfaces + implementation is "making it e= asy". For some users, perhaps, but for others, you're going to cause heada= ches due to creating classloader conflicts (when it's already bundled in th= eir application). > Technically, it's possible. But from a user perspective, not bundling= an implementation means: >=20 > - Understanding why the code I wrote fails with a "Provider org.glassfish= .json.JsonProviderImpl not found". > - Google that. Find that you need to add the dependency and very likely c= reate a SPI file (META-INF/services/javax.json.spi.JsonProvider). > - Blame PostgreSQL for not doing that by default and shipping a half-bake= d driver that is not finished (won't be my opinion, but might be user's opi= nion). > - Google again to see what JSR353-compliant implementations are out there. > - Blame PostgreSQL again for not making this choice for you. > - Struggling to find a compatible implementation. Find Jackson but realiz= e requires third-party driver. Question the "quality" of that wrapper and c= onsider whether that would be "supported" with PostgreSQL driver. > - Luckily enough a search points you to a StackOverflow link that suggest= s to use either this Jackson wrapper or the Reference Implementation (there= are not many JSR353 implementations, after all). > - Choose without knowing which JSON parser is best. > - Bundle the dependency, check now it works. Clean your sweat. > - Wonder why not to choose MongoDB next time, it works out of the box. >=20 > Not funny. >=20 > The alternative is: bundle a default (the RI) and let advanced users = not happy with the default implementation to make another choice (basically= create the META-INF/services/javax.json.spi.JsonProvider and that will ove= rride the bundled RI). You have the best of both worlds. >=20 > Pareto (https://en.wikipedia.org/wiki/Pareto_principle): let's make i= t work for 80% and let that 20% to edit a file and "suffer" a 64Kb size inc= rease in the driver, rather than ask everybody to go through the above proc= ess. >=20 >=20 >=20 >=20 > =95 If as Dave Cramer says, the PG protocol doesn't currently support st= reaming, it still makes sense to add streaming support that reads from alre= ady fully-read resources... because in that way, if the protocol improves i= n the future, client code using the streaming API will benefit (with no cha= nges to client code) in the future. > JSR353 already has a Streaming API. I don't understand what do we nee= d to do here, it's already done. >=20 > Best regards, >=20 > =C1lvaro >=20 >=20 >=20 >=20 >=20 > --=20 > =C1lvaro Hern=E1ndez Tortosa >=20=20 >=20=20 > ----------- > 8Kdata >=20=20 >=20 >=20 >=20 >=20 >=20 >=20 > -- >=20 > Christopher >=20 >=20=20 >=20 >=20=20 >=20 > On 28 June 2015 at 01:53, =C1lvaro Hern=E1ndez Tortosa w= rote: >=20 >=20=20 >=20 > On 28/06/15 00:55, Sehrope Sarkuni wrote: >=20 > On Sat, Jun 27, 2015 at 6:25 PM, =C1lvaro Hern=E1ndez Tortosa wrote: >=20 > Hi Sehrope! >=20 >=20=20 >=20 > Hi =C1lvaro! :D >=20 >=20=20 >=20 > To me, this is the least important question. If based on JSR353's SPI= , it's trivial to swap the default, included one, for another one. Just pic= king a sensible default (Jackson, for instance) is probably good enough. >=20 >=20=20 >=20 > I think I've used Jackson almost every time I've had to deal with JSON in= Java. The mapping API is pretty cool in that it lets you directly create a= n target object type. If we got the route of adding methods to PGResultSet = then we could have something like: T getJsonAsType(String, Class cla= zz) >=20 >=20 > That might be a nice addition. But I believe that goes beyond driver'= s responsibility: I think it ends when it returns you the JSON type you que= ried (JsonObject in my previous email, but I'm correcting now myself: JsonV= alue) >=20 >=20 >=20 >=20 >=20=20 >=20 > I'm not wedded to Jackson though. Honestly if JS353 is the standard then = that's what we should be using. We'd still need to figure out how to handle= older JVMs or maybe just selectively disable the feature (JDK8+?). >=20 >=20 > JSR353 is targeted for JavaSE 6 :) >=20 >=20 >=20 >=20 >=20=20 >=20 >=20 > #2 is driven a lot by #1 as depending on the parser implementation there = may be different object types returned. JSON is a bit tricky as "valid JSON= " can mean null, a scalar, an object, or an array. Most people thing of it = as just an object but "foobar" is valid JSON as well. This leads us to #3... >=20 >=20 > The object type to return has to be IMHO JsonObject: http://docs.orac= le.com/javaee/7/api/javax/json/JsonObject.html >=20 >=20=20 >=20 > Not always though. All these are valid JSON too:=20 >=20 >=20=20 >=20 > =3D> SELECT '1'::json AS num, '"test"'::json AS string, '[1,2,3]'::json A= S arr, '{"foo":"bar"}'::json AS obj; >=20 > num | string | arr | obj=20=20=20=20=20=20 >=20 > -----+--------+---------+--------------- >=20 > 1 | "test" | [1,2,3] | {"foo":"bar"} >=20 > (1 row) >=20 >=20=20 >=20 > We'll need separate getters/setters for the scalar and array types as wel= l. I agree that most people will just be using the object type though (and = maybe the array). >=20 >=20 > You are right here. Please s/JsonObject/JsonValue/g JsonValue is a co= ntainer for any of the above including objects and arrays. So it would be e= nough just with JsonValue getJsonValue(....) >=20 >=20 >=20 >=20=20 >=20 >=20 > #3 doesn't have a straight answer as there is no getJSON(...) methods in = the JDBC spec. It'd probably have to be returned via getObject(...). >=20 > An alternative is to provide PGResultSet and PGPreparedStatement classes = similar to PGConnection that provides PG extensions. They could have the ge= t/set methods (ex: getJsonScalar(...) or setJsonObject(Map .= ..)) to retrieve JSON values as specific object types (i.e. scalar, object,= array). It'd be a bit more type safe as presumably most people using json/= jsonb types know the top level type of what they're storing. >=20 >=20 > Probably adding methods to PG classes would be better than getObject = and force explicit casts. Regarding the methods, if they simply return Json= Object, you already have a full API there to parse and extract and process.= So anything that returns a JsonObject from a column (identifier or #) woul= d be enough for me. >=20 >=20=20 >=20 > For most cases I think it'd be fine. I think the custom mapping I mention= ed above would cover the rest. Anything beyond that would be a full on tran= sformation and would be very application specific. >=20 >=20 > Yepp >=20 >=20 >=20 >=20 >=20=20 >=20 > For #4 I see two possible wins. First off on the usability side, there's = some convenience to natively interfacing with json/jsonb types. It'll only = have value though if those types are the same ones that users are using in = the rest of their code. If they're just using them as Map ev= erywhere then it'd still be a pain for a user to convert to our "native" PG= JSON types to use via JDBC. Having a dedicated API that allows for interac= tion using native Java types would make this more convenient. >=20 > The other win I can see for #4 is on performance. Right now JSON is conve= rted to a String. That means everybody using it has to convert it twice. Fi= rst raw bytes to String, then String to object. A dedicated API could cut o= ne of those out of the way. Given how the wire protocol is implemented in t= he driver, it wouldn't be a direct reading from the input stream (it'll be = buffered in a byte array), but at least it won't be copied twice. >=20 >=20 > As far as I know, most users are using JsonObject, so returning that = is a perfect match for pgjdbc. I don't expect however big performance wins = as JSON is sent as a String over the wire... >=20 >=20=20 >=20 > The performance gain isn't on the wire, it's from not having to convert b= ytes =3D> String =3D> JsonObject. It'd be bytes =3D> JsonObject or bytes = =3D> CustomObject. Less work and less GC. The bigger the JSON string, the b= igger the savings too. >=20 >=20 > You are right in that JSR353 allows you to create a parser directly o= ut of an InputStream, so you would avoid converting to String. That's a win= . The rest of the conversions are inevitable (having the latter one you poi= nted out laying in user's realm, beyond driver's responsibility). >=20 > Regards, >=20 > =C1lvaro >=20 >=20 >=20 >=20 > --=20 > =C1lvaro Hern=E1ndez Tortosa >=20=20 >=20=20 > ----------- > 8Kdata >=20=20 >=20=20 >=20 >=20=20 >=20 >=20=20 >=20 >=20=20 >=20 >=20=20 >=20 >=20=20 >=20 >=20 --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc