Thread: ERROR: Could not convert UTF-8 to ISO8859-1

ERROR: Could not convert UTF-8 to ISO8859-1

From
fritz-bayer@web.de (Fritz Bayer)
Date:
Hello,

my database encodes data as utf8. The data I want to select contains
characters like äöü.

If I select some columns and change the encoding to latin1, then I get
the following error message:

select created, keywords from requests;
ERROR:  Could not convert UTF-8 to ISO8859-1

If I set the client encoding to utf8 by entering "\encoding utf8",
then the same select will print all the columns bu display

Ì for ü
ö for ö

and mess up other "special characters". The version of my postgres
installation is 7.2.1 on woody/debian.

Why does postgresql issue the error message "ERROR:  Could not convert
UTF-8 to ISO8859-1", when I execute a select statement after I changed
the client encoding to latin1 ???

fritz

Re: ERROR: Could not convert UTF-8 to ISO8859-1

From
"John D. Burger"
Date:
> Why does postgresql issue the error message "ERROR:  Could not convert
> UTF-8 to ISO8859-1", when I execute a select statement after I changed
> the client encoding to latin1 ???

Because every UTF8 character cannot necessarily be encoded as Latin1.
Unicode has more than 64,0000 characters, Latin1 has less than 256.

Check your database for non-Latin1 characaters.

> If I set the client encoding to utf8 by entering "\encoding utf8",
> then the same select will print all the columns bu display
>
> ÃŒ for ü
> ö for ö
>
> and mess up other "special characters".

This is because your display (xterm, whatever) is set to Latin1,
presumably.  There are at least three different encoding settings here:
how your data is stored in the database, what the server sends to psql,
and what your display thinks its getting.  These must all be consistent
with one another.

- John D. Burger
   MITRE