Re: 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: Re: Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns
Date: 2008-11-11 11:27:45
Message-ID: 49196C31.6010409@megafon.hr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Mario Splivalo wrote:
> But, if I want it other way around, I get the error:
>
> test1=# select envode(E'\305', 'hex');
> ERROR: invalid byte sequence for encoding "UTF8": 0xc5
> 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".
> test1=#
>
> Is there a way to circumvent encoding when dealing with binary data? Or
> am I completely confused here and have no clue what am I talking about?
>

Now, this works:

test1=# select encode(decode('C5', 'hex'), 'hex');
encode
--------
c5
(1 row)

I see that my client encoding has a problem interpreting '\xC5':

test1=# select E'\xC5';
ERROR: invalid byte sequence for encoding "UTF8": 0xc5
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".

So the only way is to use decode function, right?

Mike

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bart van Houdt 2008-11-11 13:57:20 Postgres version of all_ind_cols
Previous Message Mario Splivalo 2008-11-11 11:24:34 Re: Using UTF strings in pg8.3 - storing hexadecimal values in bytea columns