Re: length() return wrong result - Mailing list pgsql-bugs

From Heikki Linnakangas
Subject Re: length() return wrong result
Date
Msg-id 49D9DB12.7090104@enterprisedb.com
Whole thread Raw
In response to length() return wrong result  (Cédric Villemain <cedric.villemain@dalibo.com>)
List pgsql-bugs
Cédric Villemain wrote:
> - From the documentation, length(string) is 'Number of characters in string'
>
> But it didn't :
>
> 1/ in a LATIN9 database:
>
> postgres=# show server_encoding;
>  server_encoding
> - -----------------
>  LATIN9
>
> postgres=# set client_encoding = utf8;
> SET
> postgres=# select length('é');
>  length
> - --------
>       1
>
> postgres=# set client_encoding = latin9;
> SET
> postgres=# select length('é');
>  length
> - --------
>       2

I bet your console works in UTF-8, so setting client_encoding=latin9 is
not the right thing to do. If you replace "select length('é')" with
"INSERT INTO foo VALUES ('é')", and check the contents of the table with
SELECT * FROM foo afterwards, you'll see that the string is garbled in
the latter case, and indeed consists of two characters.

As you noticed, server_encoding makes no difference here.

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

pgsql-bugs by date:

Previous
From: Cédric Villemain
Date:
Subject: length() return wrong result
Next
From: Andreas Pflug
Date:
Subject: data loss with pg_standby when doing a controlled failover