Thread: language code incompatibility in Windows

language code incompatibility in Windows

From
阎兆珣
Date:

Hello!


For PG 9.1 ~ 9.5 in Windows 7 32bit

psql can not recognize Chinese database name while pgAdmin III can.

can you solve this problem?

Thanks




格林大华期货

金融衍生品部

阎兆珣

010-56711783

Q: 3130553720

Zhaoxun Yan          

Option Product Manager

Gelin Dahua Futures Co.Ltd

 T: +86 10 56711783


Re: language code incompatibility in Windows

From
Haribabu Kommi
Date:

			
		

Re: language code incompatibility in Windows

From
Noah Misch
Date:
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