Skip site navigation (1) Skip section navigation (2)

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

From: Richard Huxton <dev(at)archonet(dot)com>
To: Mario Splivalo <mario(dot)splivalo(at)megafon(dot)hr>, PostgreSQL SQL List <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns
Date: 2008-11-10 16:42:36
Message-ID: 4918647C.5070509@archonet.com (view raw or flat)
Thread:
Lists: pgsql-sql
Mario Splivalo wrote:
> Richard Huxton wrote:
>> Mario Splivalo wrote:
>>> I have this issue:
>>>
>>> postgres=# select E'\xc5\x53\x94\x96\x83\x29';
>>> ERROR:  invalid byte sequence for encoding "UTF8": 0xc553
>>
>> I think you want to be using octal escapes. That's text you're
>> generating above.
>>
>> CREATE TABLE bytea_test (b bytea);
>> INSERT INTO bytea_test (b) VALUES (E'\\305\\123\\224\\226');
>> SELECT * FROM bytea_test;
>>        b
>> ---------------
>>  \305S\224\226
>> (1 row)
> 
> That's true, but I'd still like to use hexadecimal notation. Manual
> states that I could say '\xC5', but then I get those encoding errors.

I think you're reading the "text" rather than "bytea" part of the manual.

4.1.2.1. String Constants
"...and \xhexdigits, where hexdigits represents a hexadecimal byte
value. (It is your responsibility that the byte sequences you create are
valid characters in the server character set encoding.)"

No mention of hex in the bytea section of the manual.

-- 
  Richard Huxton
  Archonet Ltd

In response to

Responses

pgsql-sql by date

Next:From: Tom LaneDate: 2008-11-10 16:57:55
Subject: Re: Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns
Previous:From: Tom LaneDate: 2008-11-10 16:26:09
Subject: Re: Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group