Re: Error "invalid byte sequence for encoding UTF8" on insert into BYTEA column

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Alan Millington <admillington(at)yahoo(dot)co(dot)uk>
Cc: Postgres general mailing list <pgsql-general(at)postgresql(dot)org>
Subject: Re: Error "invalid byte sequence for encoding UTF8" on insert into BYTEA column
Date: 2010-01-22 00:13:13
Message-ID: 20100122001312.GB22947@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jan 21, 2010 at 11:54:32AM -0800, Alan Millington wrote:
> Today for the first time since upgrading to Postgres 8.4.1 I tried
> out part of the code which inserts some binary data into a table. The
> insert failed with the error "invalid byte sequence for encoding
> UTF8". That is odd, because the column into which the insert was made
> is of type bytea: the data is meant to be binary data, not
> UTF8-encoded Unicode.

Inserting in bytea needs an extra level of escaping when the parameters
are sent inline. See

http://www.postgresql.org/docs/8.4/interactive/datatype-binary.html

> When I was using Postgres 8.1.4 the same code worked. My code, the
> mxODBC code and the driver are all unaltered: only the Postgres
> version has changed.. Is there something I can tweak to get it to
> work on Postgres 8.4.1?

Very odd. The syntax for this hasn't changed in a long time. And I
would have thought you'd be sending your paramters out of line anyway.
Can you check that?

Hope this helps,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Smith 2010-01-22 00:22:50 Re: \dt+ sizes don't include TOAST data
Previous Message Andrej 2010-01-21 23:53:30 Re: array element replace ?