Problem with binary data transfer format of TEXT in 8.4 - Mailing list pgsql-general

From Gracjan Polak
Subject Problem with binary data transfer format of TEXT in 8.4
Date
Msg-id CAChsM3RavKEntGLwCvwrF705EYBFZmMXuDKpem+hedjM8Xj7FQ@mail.gmail.com
Whole thread Raw
List pgsql-general
Hi all,

(Please redirect me to correct place if there is one).

I'm trying to implement proper binary data transfer in Database.HDBC.PostgreSQL Haskell library. This library is a wrapper around libpq.

I sorted out how to use paramFormats[] param of PQexecParams. I sorted out how to retrieve and properly unescape binary data when received with PQunescapeBytea.

Due to architecture of wrapper library I'm unable to make a difference between strings and binary data. It is all ByteString all over the place.

CREATE TABLE test( str TEXT, bytes BYTEA );

Works:

INSERT INTO test(bytes) VALUES (?)
with ["anything"]


SELECT bytes FROM test
returns ["anything"] correctly


Does not work:

INSERT INTO test(str) VALUES (?)
with ["anything"] sometimes fails with:

user error (SQL error: SqlError {seState = "08P01", seNativeError = 7, seErrorMsg = "execute: PGRES_FATAL_ERROR: ERROR:  insufficient data left in message\n"})

So it seems to me that putting string into database with binary format requires something more than just encoding it as UTF8 and stating its length in paramLengths[].


So the question is:

How do I transfer strings in binary format?

Note: I do not need binary format of anything else but UTF-8 encoded TEXT.
Note 2: I leave paramTypes[] as NULL.


Versions:

PostgreSQL 8.4
MacOSX 10.6
postgresql, bound to client: 8.4.9
Proxied driver: postgresql, bound to version: 3
Connected to server version: 80409

-- 
Gracjan

pgsql-general by date:

Previous
From: Adarsh Sharma
Date:
Subject: How to get Place Names from Lat Lon
Next
From: tamanna madaan
Date:
Subject: Re: psql query gets stuck indefinitely