pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: Markus Schaber <schabios@logi-track.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: How to insert binary data
Date: Sat, 05 Jun 2004 21:30:33 +1200
Message-ID: <40C192B9.5000203@opencloud.com> (raw)
In-Reply-To: <20040604151952.3ad9369a@kingfisher.intern.logi-track.com>
References: <20040604151952.3ad9369a@kingfisher.intern.logi-track.com>

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



view thread (3+ messages)  latest in thread

Message-ID: <40C192B9.5000203@opencloud.com>
Permalink:  ../40C192B9.5000203@opencloud.com/
Also on:    postgresql.org/message-id/40C192B9.5000203@opencloud.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: oliver@opencloud.com, schabios@logi-track.com
  Subject: Re: How to insert binary data
  In-Reply-To: <40C192B9.5000203@opencloud.com>
  References: <20040604151952.3ad9369a@kingfisher.intern.logi-track.com> <40C192B9.5000203@opencloud.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox