Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns

From: Mario Splivalo <mario(dot)splivalo(at)megafon(dot)hr>
To: pgsql-sql(at)postgresql(dot)org
Subject: Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns
Date: 2008-11-10 14:01:33
Message-ID: 49183EBD.7070807@megafon.hr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

----------------------------------------------------------------------------------------------------------------
PostgreSQL 8.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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Mario Splivalo 2008-11-10 14:34:10 Converting between UUID and VARCHAR
Previous Message Sebastian Ritter 2008-11-10 13:39:50 Re: Query optimizing