Обсуждение: about encoding

Поиск
Список
Период
Сортировка

about encoding

От
superman0920
Дата:
hello
i want to insert a report to postgresql,the report contain something Chinese characters and the postgresql is utf-8.
the response from db is this:
ERROR:  invalid byte sequence for encoding "UTF8": 0xb1
 
how can i fix it ?
 
thx
 

superman0920

Re: about encoding

От
Steve Crawford
Дата:
On 03/28/2012 08:00 PM, superman0920 wrote:
BLOCKQUOTE {MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 2em } OL {MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px } UL {MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px } P {MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px } BODY {LINE-HEIGHT: 1.5; FONT-FAMILY: 微软雅黑; COLOR: #000000; FONT-SIZE: 10.5pt }
hello
i want to insert a report to postgresql,the report contain something Chinese characters and the postgresql is utf-8.
the response from db is this:
ERROR:  invalid byte sequence for encoding "UTF8": 0xb1
 
how can i fix it ?
 

<snark>Remove the bad character??</snark>

You need to provide a bit more information, but the likely cause is that the data you are inserting is not UTF8 encoded. Check the system that is generating the data you wish to insert and make sure it is set to write its output as UTF8.

If you cannot set it to write UTF8, then you need to determine what character-set it is using and tell PostgreSQL to use that. See "SET client_encoding..." Note that UTF8 is the character set that PostgreSQL is using internally but you can read and write other sets through the client_encoding setting.

Also be aware that UTF8 is just one of many ways of encoding the various Unicode code-points. People sometimes conversationally interchange Unicode and UTF8 but they are not the same. Make sure that the data you are receiving is specifically UTF8 and not just some unknown Unicode encoding.

If you are still stuck after checking/fixing the above you could actually have bad data in your input or, possibly, an incorrect byte-order issue though that is unlikely in most situations.

Cheers,
Steve