Lists: | pgsql-bugs |
---|
From: | Cédric Villemain <cedric(dot)villemain(at)dalibo(dot)com> |
---|---|
To: | pgsql-bugs(at)postgresql(dot)org |
Subject: | length() return wrong result |
Date: | 2009-04-06 09:03:00 |
Message-ID: | 49D9C544.7030108@dalibo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-bugs |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi,
- 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
2/ in a UTF8 database:
postgres=# show server_encoding;
server_encoding
- -----------------
UTF8
postgres=# set client_encoding = utf8;
SET
postgres=# select length('é');
length
- --------
1
postgres=# set client_encoding = latin9;
SET
postgres=# select length('é');
length
- --------
2
- --
Cédric Villemain
Administrateur de Base de Données
Cel: +33 (0)6 74 15 56 53
http://dalibo.com - http://dalibo.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAknZxUQACgkQo/dppWjpEvyi+wCeNAB3706M2iSwUJGMWAQsCWyi
YRgAoJKwDRq6esZeMmnFdOAtq2d4kqoP
=6mds
-----END PGP SIGNATURE-----
From: | Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com> |
---|---|
To: | Cédric Villemain <cedric(dot)villemain(at)dalibo(dot)com> |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: length() return wrong result |
Date: | 2009-04-06 10:36:02 |
Message-ID: | 49D9DB12.7090104@enterprisedb.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | 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