Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 035BA1337B54 for ; Tue, 8 Feb 2011 05:28:23 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 07487-02 for ; Tue, 8 Feb 2011 09:28:16 +0000 (UTC) X-Greylist: delayed 00:25:15.995205 by SQLgrey-1.7.6 Received: from prod2.officenet.no (unknown [195.159.87.248]) by mail.postgresql.org (Postfix) with ESMTP id 277861337B4F for ; Tue, 8 Feb 2011 05:28:14 -0400 (AST) Received: from localhost ([127.0.0.1] helo=prod2) by prod2.officenet.no with esmtp (Exim 4.71) (envelope-from ) id 1PmjTM-00084V-Rd for pgsql-jdbc@postgresql.org; Tue, 08 Feb 2011 10:02:56 +0100 Date: Tue, 8 Feb 2011 10:02:55 +0100 (CET) From: Andreas Joseph Krogh To: pgsql-jdbc@postgresql.org Message-ID: <11083803.58.1297155775319.JavaMail.on@prod2> In-Reply-To: <4D509403.4070905@opencloud.com> Subject: Re: ResultSet.getClob() causing problems when used with JPA's @Lob MIME-Version: 1.0 User-Agent: Origo 1.8.9-SNAPSHOT X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.107 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RDNS_NONE=0.793 X-Spam-Level: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Archive-Number: 201102/40 X-Sequence-Number: 21438 P=C3=A5 tirsdag 08. februar 2011 kl 01:53:23 skrev "Oliver Jowett" : > On 08/02/11 12:25, Andreas Joseph Krogh wrote: > > On 02/07/2011 10:38 PM, Rados=C5=82aw Smogura wrote: > >> PostgreSQL doesn't have field type CLOB, nor BLOB.=20 > >=20 > > I know that. > >=20 > >> If eveny it would be possible for driver to read CLOB from varchar, dr= iver=20 > >> will be unable to set proper value when calling UPDATE or INSTERT. It = is due=20 > >> to internal way how PSQL deals with those values. > >=20 > > Isn't the whole concept of CLOB just a bi-product of old proprietary > > database-design where some RDBMS'es are unable to store arbitrary long > > varchars? What properties do CLOBs have that varchars don't, except > > being large? I don't understand why CLOBs can't be treated like text in > > the PG-driver as PG handles large Strings just fine in > > varchar/text-columns. If a DBA has for some reason defined a scale, say > > VARCHAR(10), on a column and tries to store a CLOB in it, well - his > > problem; He should get an Exception from PG. >=20 > The different property is that clobs are mapped to OIDs that reference > an externally-stored LOB. So at the most basic "what do I get from the > server?" level they're different to varchar - the column type is an OID, > not varchar, so you have to send/receive OID values not strings and > perform a separate step to manage the data referenced by the OID. >=20 > They're mostly superceded by bytea/text, but they do still have some > properties that mean they do not behave identically (e.g. they are > essentially pass-by-reference, not pass-by-value; and you can modify > parts of them in-place without passing around the whole value). Firstly; My issue here only affects CLOBs, not BLOBs. Secondly; I'm not trying to be anal here, just trying to understand the arg= uments. Thirdly; Didn't we just agree on that PG doesn't have CLOBs? If PG doesn't = have CLOBs, how can it map CLOBs to OIDs? Under what circumstances would PG= need an OID to map a *C*LOB? Are you suggesting to store CLOBs as bytea? I= s anyone doing this? > >> I know drivers supports custom casting, but casting from varchar to cl= ob is=20 > >> implicite prohibted in JDBC. If you look at B-6 table x indicates poss= ible=20 > >> casting. There is no x, nor X on varchar cross clob > >=20 > > Does it not make sense to you to be able to cast a *character large > > object* to a *variable length character*-type and visa versa? > >=20 > > If the only argument is spec-complience I'm not getting it... >=20 > Conceivably, the driver could notice that a column is a varchar and > expose it via a different implementation of the clob interface that > doesn't try to interpret the value as an OID identifying an underlying > LOB. But that's not currently done because it's not one of the required > JDBC conversions (so if you expect that behavior from an arbitrary > driver you're already on shaky ground) and there's been no requests for > it before this that I can remember offhand. Also, the reverse conversion > isn't going to work, as mentioned above, so I don't know how useful it'd > be to you (the driver knows it got a varchar in a resultset, but in > general it won't know that when you said PreparedStatement.setClob() you > actually meant "please turn this into a varchar and insert that, instead > of creating a LOB and inserting the OID as you usually would"). You > could make it a big connection-wide toggle that said whether to > interpret clobs as LOBs or varchars, I suppose, but that's rather a big > hammer to fix what is arguably a problem in your persistence layer. (For > example, why can't you tell Hibernate exactly the same thing - "please > interpret my character LOBs as varchars" - which would be presumably be > useful to more than just the postgresql driver?) All this stuff sounds like an implementation detail to me. The programmer u= sing JDBC should, IMO, be able to use rs.setClob() to varchar/text-columns = transparently as there's no reason to treat it differently than setString(). > The fundamental question here is "why are you trying to map a varchar to > a Clob?" .. As you say, clobs are mostly redundant anyway. Given that > your schema uses varchar, why don't you just use the varchar-style > accessors? It's not unreasonable to expect your access method to match > the underlying schema, surely. The reason I map the String-property as @Lob (which, by default, makes Hibe= rnate use setClob()) is for interoperability with other DBs, like Oracle, w= hich require this annotation in order to be able to store Strings which are= over 4000 chars long. These properties are stored in Oracle as CLOB and in= PG as VARCHAR. -- Andreas Joseph Krogh Senior Software Developer / CTO Public key: http://home.officenet.no/~andreak/public_key.asc ------------------------+---------------------------------------------+ OfficeNet AS | The most difficult thing in the world is to | Rosenholmveien 25 | know how to do a thing and to watch | 1414 Troll=C3=A5sen | somebody else doing it wrong, without | NORWAY | comment. | Org.nr: NO 981 479 076 | | | | Tlf: +47 24 15 38 90 | | Fax: +47 24 15 38 91 | | Mobile: +47 909 56 963 | | ------------------------+---------------------------------------------+