Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns - Mailing list pgsql-sql

From Mario Splivalo
Subject Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns
Date
Msg-id 49183EBD.7070807@megafon.hr
Whole thread Raw
Responses Re: Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns
List pgsql-sql
I have this issue:

postgres=# select E'\xc5\x53\x94\x96\x83\x29';
ERROR:  invalid byte sequence for encoding "UTF8": 0xc553
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".
postgres=# show client_encoding ; client_encoding
----------------- UTF8
(1 row)

postgres=# show server_encoding ; server_encoding
----------------- UTF8
(1 row)

postgres=# select version();                                            version 

------------------------------------------------------------------------------------------------ PostgreSQL 8.3.5 on
i686-pc-linux-gnu,compiled by GCC gcc (GCC) 4.2.4 
 
(Ubuntu 4.2.4-1ubuntu3)
(1 row)




On postgres 8.2 this worked:

postgres=# select version();                                                    version 

----------------------------------------------------------------------------------------------------------------
PostgreSQL8.2.4 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 
 
20061115 (prerelease) (Debian 4.1.1-21)
(1 row)

postgres=# select E'\xc5\x53\x94\x96\x83\x29'; ?column?
---------- S)
(1 row)

postgres=# show client_encoding ; client_encoding
----------------- UTF8
(1 row)

postgres=# show server_encoding ; server_encoding
----------------- UTF8
(1 row)


I'm using the above mentioned string to store data into bytea column. I 
did pg_dump of the database on postgres 8.2, and then tried to restore 
it on postgres 8.3, and I got this error. The actuall line that produces 
error is like this:

INSERT INTO vpn_payins_bitfield (vpn_id, payload_pattern, encription, 
encription_key, charset, amount_width, shop_width, counter_width) VALUES 
(3, E'\\W*(\\w+)(?:\\W+(.*))?', 'RC4', 
E'\xc5\x53\x94\x96\x83\x29'::bytea, 'ABCDEGHIKLMOPTWX', 16, 8, 16);

The error is:
ERROR: invalid byte sequence for encoding "UTF8": 0xc553


Now, I see that I can type: "SELECT E'\xFF'" in pg8.2, but can't do that 
in pg8.3.

So, my question is, how do I specify hexadecimal value of C5 to be 
stored in bytea column, in an INSERT statement?
Mike


pgsql-sql by date:

Previous
From: "Sebastian Ritter"
Date:
Subject: Re: Query optimizing
Next
From: Mario Splivalo
Date:
Subject: Converting between UUID and VARCHAR