Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id B7AB81782AF6 for ; Mon, 2 Apr 2012 12:55:38 -0300 (ADT) Received: from cerberus.pinpointresearch.com ([66.7.238.130] helo=polaris.pinpointresearch.com) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SEjbV-0002g5-CL for pgsql-admin@postgresql.org; Mon, 02 Apr 2012 15:55:38 +0000 Received: from betelgeuse.pinpointresearch.com (betelgeuse.pinpointresearch.com [192.168.1.179]) by polaris.pinpointresearch.com (Postfix) with ESMTP id BD4DAE00EC83; Mon, 2 Apr 2012 08:55:23 -0700 (PDT) Message-ID: <4F79CBEC.7080805@pinpointresearch.com> Date: Mon, 02 Apr 2012 08:55:24 -0700 From: Steve Crawford User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.27) Gecko/20120216 Lightning/1.0b2 Thunderbird/3.1.19 MIME-Version: 1.0 To: superman0920 CC: pgsql-admin Subject: Re: about encoding References: <201203291100302033066@gmail.com> In-Reply-To: <201203291100302033066@gmail.com> Content-Type: multipart/alternative; boundary="------------030006060201060101020103" X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201204/2 X-Sequence-Number: 39338 This is a multi-part message in MIME format. --------------030006060201060101020103 Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: quoted-printable On 03/28/2012 08:00 PM, superman0920 wrote: > hello > i want to insert a report to postgresql=A3=ACthe report contain somethi= ng > 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 ? > Remove the bad character?? 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 --------------030006060201060101020103 Content-Type: text/html; charset=GB2312 Content-Transfer-Encoding: quoted-printable On 03/28/2012 08:00 PM, superman0920 wrote:
hello
i want to insert a report to postgresql=A3=ACthe report contai= n something Chinese characters and the postgresql is utf-8.
the response from db is this:
ERROR:  invalid&nbs= p;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

--------------030006060201060101020103--