X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 42541D1B1D1 for ; Sat, 5 Jun 2004 13:03:46 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 78092-08 for ; Sat, 5 Jun 2004 16:03:44 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 75D9ED1B18C for ; Sat, 5 Jun 2004 07:14:32 -0300 (ADT) Received: from p51-max2.pmr.ihug.co.nz ([203.173.220.115] helo=opencloud.com) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1BWYBy-0000f7-00; Sat, 05 Jun 2004 22:14:24 +1200 Message-ID: <40C192B9.5000203@opencloud.com> Date: Sat, 05 Jun 2004 21:30:33 +1200 From: Oliver Jowett User-Agent: Mozilla Thunderbird 0.5 (Windows/20040207) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Markus Schaber Cc: pgsql-jdbc@postgresql.org Subject: Re: How to insert binary data References: <20040604151952.3ad9369a@kingfisher.intern.logi-track.com> In-Reply-To: <20040604151952.3ad9369a@kingfisher.intern.logi-track.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.1 tagged_above=0.0 required=5.0 tests=RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200406/21 X-Sequence-Number: 10223 Markus Schaber wrote: > Hi, > > Today, I had some problems inserting Data via WKB format (which we > suspect to be more efficient compared to the text representation) into a > PostGIS database through JDBC. What is the "WKB" representation exactly? (I'm guessing "well known binary"?) > We have the data as a byte array, but either > PreparedStatement.setBytes() and .setObject() failed to work. > > After some experimentation, I found that I have to encode the byte array > into hex, and then it works (which is ugly because we need to > pre-process the data and double the data size). > > For retreiving wkb data, there is a bytea() function that returns the > binary data, but there seems to be no constructor for wkb postgres type > that uses binary data. > > It also looks like the PGObject subclassing mechanism only works for > String representations, and the JDBC TypeMap mechanism is not > implemented. > > Is there any way that allows efficient storing of WKB data into PostGIS? The standard driver can't use binary parameter values as it does not use the extended query protocol for sending parameters. I'm working on some driver modifications that would allow sending parameters in a binary form (among other things). The main unresolved question in this area is how it would fit with the PGobject system. My current thoughts are to have a PGBinaryObject subclass of PGobject that has methods for streaming the parameter in a binary form. The addDataType registration mechanism would remain unchanged, and you'd continue to use setObject to bind parameters. At statement execution time, if the bound parameter value subclasses PGBinaryObject *and* the protocol in use allows use of binary parameters (version 2 connections won't) then the appropriate PGBinaryObject methods are invoked to actually send the parameter. Otherwise the driver uses the current string representation approach. Getting results back in a binary form is further away but would use a similar strategy (if we have a binary result value and a corresponding registered type that subclasses PGBinaryObject, call an appropriate method, otherwise treat it as an unknown type). Does this sound like the right approach for what you need? -O