Error inserting data to bytea column in 8.4

Started by Andrusover 16 years ago3 messagesgeneral
Jump to latest
#1Andrus
kobruleht2@hot.ee

In 8.4, script

create temp table test ( test bytea );
insert into test values(E'\274')

Causes error

ERROR: invalid byte sequence for encoding "UTF8": 0xbc
HINT: This error can also happen if the byte sequence does not match the
encoding expected by the server, which is controlled by "client_encoding".

In 8.2 this script runs OK.

How to insert data to bytea field ?

Andrus

Both server and client are running in windows.

"PostgreSQL 8.4.0, compiled by Visual C++ build 1400, 32-bit"

show client_encoding
"UNICODE"

#2Bruce Momjian
bruce@momjian.us
In reply to: Andrus (#1)
Re: Error inserting data to bytea column in 8.4

2009/8/21 Andrus Moor <kobruleht2@hot.ee>:

In 8.4, script

create temp table test ( test bytea );
insert into test values(E'\274')

Try E'\\274'

--
greg
http://mit.edu/~gsstark/resume.pdf

#3Sam Mason
sam@samason.me.uk
In reply to: Andrus (#1)
Re: Error inserting data to bytea column in 8.4

On Fri, Aug 21, 2009 at 06:54:51PM +0300, Andrus Moor wrote:

create temp table test ( test bytea );
insert into test values(E'\274')

Causes error

Yup, you want another backslash in there, something like:

insert into test values(E'\\274');

The first backslash is expanded out during parsing the SQL into a
literal and the second during parsing of the literal into a bytea value.
You've got the following transformation going on:

SQL -> Literal -> Bytea value

The character values at each stage go like this:

SQL : 5c 5c 32 37 34
Literal : 5c 32 37 34 (because the '\\' has been unescaped to a '\')
Bytea : bc

In 8.2 this script runs OK.

Maybe it's in SQL_ASCII encoding? NUL characters wouldn't work in your
8.2 database if that's the case.

--
Sam http://samason.me.uk/