Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VHqpZ-0001fI-Bu for pgsql-sql@arkaria.postgresql.org; Fri, 06 Sep 2013 07:51:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VHqpY-0000WH-LY for pgsql-sql@arkaria.postgresql.org; Fri, 06 Sep 2013 07:51:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VHqpX-0000WA-J2 for pgsql-sql@postgresql.org; Fri, 06 Sep 2013 07:51:47 +0000 Received: from mail231.strasbourg.4js.com ([92.103.31.231]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VHqpQ-0006qr-CR for pgsql-sql@postgresql.org; Fri, 06 Sep 2013 07:51:47 +0000 Received: from [10.0.0.204] (orca.strasbourg.4js.com [10.0.0.204]) (authenticated bits=0) by mail231.strasbourg.4js.com (8.14.4/8.14.4/Debian-4) with ESMTP id r867pcLq023588 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NOT) for ; Fri, 6 Sep 2013 09:51:38 +0200 Message-ID: <52298A02.4060607@4js.com> Date: Fri, 06 Sep 2013 09:53:38 +0200 From: Sebastien FLAESCH Organization: Four Js Development Tools User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20111110 Lightning/1.0b1 Icedove/3.0.11 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Understanding Encoding References: <20130906.160312.318878479653679358.t-ishii@sraoss.co.jp> In-Reply-To: <20130906.160312.318878479653679358.t-ishii@sraoss.co.jp> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: clamav-milter 0.97.8 at mail231 X-Virus-Status: Clean X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.4.3 (mail231.strasbourg.4js.com [10.10.0.1]); Fri, 06 Sep 2013 09:51:38 +0200 (CEST) X-Pg-Spam-Score: -4.3 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Hi, Tip: To identify what encoding you enter in the psql command interpreter: 1) Open a file with vim 2) Type in you SQL or copy/paste 3) Save the file and quit vim 4) $ file Should give you the encoding of that text file. For ex: sf@orca:~$ echo $LC_ALL en_US.UTF-8 sf@orca:~$ cat /tmp/xx abcdefé sf@orca:~$ file /tmp/xx /tmp/xx: UTF-8 Unicode text Seb On 09/06/2013 09:03 AM, Tatsuo Ishii wrote: >> Hello All, >> >> I am not able to understand how the encoding is handled. I would be happy >> if someone can tell what is happening in the following scenario: >> >> 1. I have created a database with EUC_KR encoding and created a table and >> inserted some korean value into it. >> >> =# CREATE DATABASE korean WITH ENCODING 'EUC_KR' LC_COLLATE='ko_KR.euckr' >> LC_CTYPE='ko_KR.euckr' TEMPLATE=template0; >> >> =# \c korean >> >> korean=# SHOW client_encoding; >> client_encoding >> ----------------- >> UTF8 >> (1 row) >> >> korean=# CREATE TABLE tbl (doc text); >> >> korean=# INSERT INTO tbl VALUES ('그레스'); >> >> >> 2. If I insert non-korean values it throws error: >> >> korean=# INSERT INTO tbl VALUES ('データベース'); >> ERROR: character with byte sequence 0xe3 0x83 0xbc in encoding "UTF8" has >> no equivalent in encoding "EUC_KR" > > The error messages says all. PostgreSQL accepted 'データベース' > encoded in UTF-8 then tried to convert to EUC_KR but failed, because > EUC_KR does not accept languages other than Korean (and ASCII). What > else did you expect? > >> korean=# SELECT * FROM tbl; >> doc >> -------- >> 그레스 >> (1 row) >> >> >> 3. I change the client encoding to EUC_KR and try inserting the same korean >> characters and it throws an error: >> >> korean=# SET client_encoding = 'EUC_KR'; >> SET >> korean=# INSERT INTO tbl VALUES ('그레스'); >> ERROR: invalid byte sequence for encoding "EUC_KR": 0xa0 0x88 > > 0xa0 is definitely not part of EUC_KR. That's why PostgreSQL throws an > error. I gues you are using UHC (Unified Hangul Code), rather than > EUC_KR. They are different encodings. You should do either: > > 1) Make sure that your termical encoding is EUC_KR. > > 2) set client_encoding = 'uhc'; > >> Even the SELECT statement displays something different. I am not able to >> understand why? >> >> korean=# SELECT * FROM tbl; >> doc >> -------- >> �׷��� >> (1 row) > > This is because the same reason above. > >> Can someone please help me. >> >> Thanks you, >> >> Beena Emerson > -- > Tatsuo Ishii > SRA OSS, Inc. Japan > English: http://www.sraoss.co.jp/index_en.php > Japanese: http://www.sraoss.co.jp > -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql