Re: Confused with db client encoding

From: Ian Barwick <barwick(at)gmail(dot)com>
To: Carlos Correia <carlos(at)m16e(dot)com>
Cc: Lista geralPostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Confused with db client encoding
Date: 2004-09-06 15:51:15
Message-ID: 1d581afe04090608511a3d9a2f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 06 Sep 2004 00:02:24 +0100, Carlos Correia <carlos(at)m16e(dot)com> wrote:
> Hi,
>
> Here is the output a psql session. Please notice that the identation
> inconsistences in the records containg non ASCII chars is as outputed by
> psql.
>
> The db was created with LANIN9 and the console was ran (in the same
> machine) using UTF-8 (my system's default).
>
> I was surprised to notice that setting the client to unicode (which is
> what that console is using) messed the localized chars as I was
> expecting to see the opposite way.
>
> On the other way, when invoking from a Java app, running on the same
> machine, the accentuaded chars also appeared messed.

(...)
> 3 | Tx. Dinheiro | Transacções a Dinheiro
> 11 | Nota de Crédito | Notas de Crédito
> 12 | Nota de Débito | Notas de Débito
> 21 | G. Remessa | Guia de Remessa

It looks like this data was entered as UTF-8 but the client encoding
was LATIN9 (or whatever), meaning the two incoming bytes from each
accentuated character in UTF-8 was interpreted by the backend as two
individual bytes in LATINx.

Test case (session in a UTF-8 environment):

test=# CREATE DATABASE ctest encoding 'LATIN1';
CREATE DATABASE
test=# \c ctest;
You are now connected to database "ctest".
ctest=# CREATE TABLE coding (data TEXT);
CREATE TABLE
ctest=# SET client_encoding TO LATIN1;
SET
ctest=# INSERT INTO coding VALUES('müller');
INSERT 349960 1
ctest=# SELECT * FROM coding;
data
---------
müller
(1 row)

ctest=# SET client_encoding TO UNICODE;
SET
ctest=# SELECT * FROM coding;
data
---------
müller
(1 row)

Ian Barwick

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-09-06 16:25:11 Re: tg_relation doesn't seem to have the attribute names!
Previous Message Randy Yates 2004-09-06 14:38:11 Re: One Database per Data File?