Re: Error "invalid byte sequence for encoding UTF8" on insert into BYTEA column - Mailing list pgsql-general

From Tom Lane
Subject Re: Error "invalid byte sequence for encoding UTF8" on insert into BYTEA column
Date
Msg-id 1274.1264175315@sss.pgh.pa.us
Whole thread Raw
In response to Re: Error "invalid byte sequence for encoding UTF8" on insert into BYTEA column  (Alan Millington <admillington@yahoo.co.uk>)
Responses Re: Error "invalid byte sequence for encoding UTF8" on insert into BYTEA column  (Alan Millington <admillington@yahoo.co.uk>)
List pgsql-general
Alan Millington <admillington@yahoo.co.uk> writes:
> What I send to mxODBC is the command as a string containing placeholders (question marks), e.g. "insert into mytable
(intcol,byteacol) values (?, ?)", plus the actual values as separate arguments, e.g. 1, data (where 1 is a literal and
datais a Python variable containing binary data). What mxODBC does with this I have no idea. It is a black box as far
asI am concerned. 

You probably need to ask the mxODBC developers (who AFAIK don't hang out
on this list) what they are doing with that data.  It sounds fairly
likely to me that the bytea value is just being sent as a string without
any special encoding.  That would explain both the null sensitivity you
mention later in the thread, and the encoding validity complaints ---
PG 8.1 was much less picky about string encoding validity than recent
versions are.

There are basically two ways that you could make this work reliably:
arrange for the bytea value to be sent as an out-of-line binary
parameter, or encode it using backslash sequences (eg, '\000' for a
null).  Whether the former is possible with mxODBC I dunno.  The latter
might be something that mxODBC will do for you if it knows the value
is supposed to be bytea, but without that knowledge I don't see how it
could.  You might end up having to do the encoding yourself.

            regards, tom lane

pgsql-general by date:

Previous
From: Raymond O'Donnell
Date:
Subject: Re: DDL question
Next
From: Tom Lane
Date:
Subject: Re: more docs on extending postgres in C