Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UUHkq-0002uM-NG for pgsql-bugs@arkaria.postgresql.org; Mon, 22 Apr 2013 14:30:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UUHkq-0006hV-4l for pgsql-bugs@arkaria.postgresql.org; Mon, 22 Apr 2013 14:30:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UUHUH-000574-7O for pgsql-bugs@postgresql.org; Mon, 22 Apr 2013 14:12:57 +0000 Received: from mahout.postgresql.org ([2001:4800:7903:4::123]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UUHU8-0002uj-7L for pgsql-bugs@postgresql.org; Mon, 22 Apr 2013 14:12:56 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UUHU6-0002my-HM for pgsql-bugs@postgresql.org; Mon, 22 Apr 2013 14:12:47 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1UUHU1-0000iG-BT for pgsql-bugs@postgresql.org; Mon, 22 Apr 2013 14:12:41 +0000 Date: Mon, 22 Apr 2013 14:12:41 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #8105: names are transformed to lowercase incorrectly To: pgsql-bugs@postgresql.org From: pg@kolesar.hu X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 8105 Logged by: Andr=C3=A1s Koles=C3=A1r Email address: pg@kolesar.hu PostgreSQL version: 9.1.5 Operating system: Windows=20 Description:=20=20=20=20=20=20=20=20 If I specify an unicode field name without quotes, field name gets lowecased incorrectly. pgAdmin 1.14.2 on Linux, PostgreSQL server 9.1.5 on Windows: SELECT =C3=A9rt=C3=A9k FROM (SELECT 1 AS "=C3=A9rt=C3=A9k") AS x; ********** Error ********** SQL state: 42703 Character: 8 In the example above I specify an unicode column name ("=C3=A9rt=C3=A9k" me= ans "value" in Hungarian), then I try to read it. If I use double quotes in the outer query, it works. However, the above example works fine if the server runs on Linux: "PostgreSQL 9.1.9 on i686-pc-linux-gnu, compiled by gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2, 32-bit" I see the same problem from PHP client. There is a more verbose error message: ERROR: column "=EF=BF=BDrt=EF=BF=BDk" does not exist LINE 1: SELECT =C3=A9rt=C3=A9k FROM (SELECT 1 AS "=C3=A9rt=C3=A9k") AS x ^ The "=C3=A9" character is represented incorrectly in the error message, it = shows where the problem is. This character (U+00E9) is represented in UTF8 as C3 A9. In the error message it is an invalid UTF8 sequence: E3 A9. I think Windows uses Windows-1250 or Windows-1252 character set where C3 lowers to E3. A9 survives tolower() because it means =C2=A9 (copyright sign) in these charsets, without lowercase pair. I have localized the problem in PostgreSQL source: src/backend/parser/scansup.c:128 char * downcase_truncate_identifier(const char *ident, int len, bool warn) { // ... for (i =3D 0; i < len; i++) // ... if (IS_HIGHBIT_SET(ch) && isupper(ch)) ch =3D tolower(ch); This function walks through identifiers byte-by-byte, lowers them if they were individual characters. This is incorrect in multibyte character sets. It works on Linux with UTF8 system encoding because isupper() returns false both for C3 and A9. The same issue is reported below: Database object names and libpq in UTF-8 locale on Windows http://permalink.gmane.org/gmane.comp.db.postgresql.sql/29464 Solution 1: tolower() only A-Z. Solution 2: use a lowercase function that uses client_encoding --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs