Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 85803ADDCB9 for ; Sat, 14 Apr 2012 01:01:34 -0300 (ADT) Received: from mail-pz0-f46.google.com ([209.85.210.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SIuB3-0000x1-8d for pgsql-admin@postgresql.org; Sat, 14 Apr 2012 04:01:34 +0000 Received: by dadz9 with SMTP id z9so5271246dad.33 for ; Fri, 13 Apr 2012 21:01:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=/hzmOxi0H23KzvR/D2V9QVkmjcY3dyu/rbFjX/FycYs=; b=mlDB66pbKrLhNRxsgMhENCh9T46dKEYRn04tGgzlPVPLuxb7Adr4g+mjDVPB2tkYcN wkGE5Ja7ibPsMeicLPvwB1T/v4dYLUsc/jwO7oewMj33ShEgf3C6vZd3tQmznFcEnY9A mrtgYVHNwvYbf/rpmuO55nF+eBoHD3QfE9yk7fYGt0trsItju7IeHkYWTjgLPGdWJsMk pAICIL4i73JPpalJhVMSgFderjTX64WFFyYrP70NMZD4Ezj18BNIhaAv6Im8Y1r7yJyO olvp6TK8j1PCzFZp7dUgls77s81WLsy/V4ciblWGkUSOF6WxpwRljRuGG0DSFMW8Cnpq I0zw== Received: by 10.68.201.73 with SMTP id jy9mr9688248pbc.35.1334376080582; Fri, 13 Apr 2012 21:01:20 -0700 (PDT) Received: from [192.168.11.3] ([114.95.165.117]) by mx.google.com with ESMTPS id qb8sm911083pbb.12.2012.04.13.21.01.12 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 13 Apr 2012 21:01:19 -0700 (PDT) Message-ID: <4F88F684.3030405@gmail.com> Date: Sat, 14 Apr 2012 12:01:08 +0800 From: Rural Hunter User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 To: raghu ram CC: pgsql-admin@postgresql.org Subject: Re: invalid byte sequence for encoding "UTF8": 0xf481 - how could this happen? References: <4F88DB40.9070609@gmail.com> In-Reply-To: Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201204/69 X-Sequence-Number: 39405 doesn't work either.

db=# show client_encoding;
 client_encoding
-----------------
 UTF8
(1 row)

db=# set client_encoding='LATIN1';
SET
db=# show client_encoding;
 client_encoding
-----------------
 LATIN1
(1 row)

db=# select to_tsvector(content) from tmp_article;
ERROR:  invalid byte sequence for encoding "UTF8": 0xf481

于 2012/4/14 10:15, raghu ram 写道:


2012/4/14 Rural Hunter <ruralhunter@gmail.com>
My db is in utf-8, I have a row in my table say tmp_article and I wanted to generate ts_vector from the article content:
select to_tsvector(content) from tmp_article;
But I got this error:
ERROR:  invalid byte sequence for encoding "UTF8": 0xf481

I am wondering how this could happen. I think if there was invalid UTF8 bytes in the content, it shouldn't have been able to inserted into the tmp_article table as I sometimes see similar errors when inserting records to tmp_article. Am I right?


This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".

Try to set client_encoding='LATIN1' 

and then execute 

select to_tsvector(content) from tmp_article;

--

Thanks & Regards,

Raghu Ram

EnterpriseDB: http://www.enterprisedb.com