Re: language code incompatibility in Windows

From: Noah Misch <noah(at)leadboat(dot)com>
To: 阎兆珣 <yanzhaoxun(at)greendh(dot)com>
Cc: pgsql-bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: language code incompatibility in Windows
Date: 2016-10-11 06:42:18
Message-ID: 20161011064218.GA1041260@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Wed, Sep 07, 2016 at 11:02:28AM +0800, 阎兆珣 wrote:
> For PG 9.1 ~ 9.5 in Windows 7 32bit
>
> psql can not recognize Chinese database name while pgAdmin III can.
>
> psql_Chinese

This is probably a symptom of a character encoding mismatch. You ran psql in
a console window, so psql received your input encoded with the console input
code page. Based on [1], pgAdmin III probably used UTF8 encoding in your
environment. The default console input code page depends on locale settings,
but it is never UTF8.

This C program demonstrates psql's ability to connect to a Chinese-named
database on Windows (tested with binaries from [2]):

/* initdb --locale=C --encoding=UTF8 */
#include <stdlib.h>
int main(int argc, char **argv)
{
system("createdb \xe5\xa3\xa4");
system("psql -c "
"\"select current_database(), octet_length(current_database())\" "
"\xe5\xa3\xa4");
return 0;
}

I recommend against non-ASCII characters in database names. PostgreSQL
performs encoding conversion, according to the client_encoding setting, on
most of the database session. It does not convert database names; it largely
treats them as byte sequences, not text. Non-ASCII database names work fine
if every client program uses the same encoding; otherwise, they create the
trouble you're experiencing. Avoid non-ASCII role names, too, for the same
reasons.

[1] https://www.postgresql.org/message-id/CA%2BOCxozjhM5wAj84vjRNWX5TLEYEMYeh37U%3DibJt22m5nqtJmA@mail.gmail.com
[2] http://get.enterprisedb.com/postgresql/postgresql-9.5.4-2-windows-x64-binaries.zip

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Grigory Smolkin 2016-10-11 10:01:15 parallel plan in insert query
Previous Message Tilo Sloboda 2016-10-10 21:41:18 Re: BUG #14362: Postgres macaddr does not support EUI-64 8-byte MAC addresses