Postgresql: Encoding Problems on Windows When Using Psql Command Line Utility

PostgreSQL: encoding problems on Windows when using psql command line utility

Thanks a lot Craig Ringer, works, finally works! You are my new idool now!

The steps are:

  1. open the cmd
  2. SET PGCLIENTENCODING=utf-8
  3. chcp 65001
  4. psql -h your.ip.addr.ess -U postgres

PostgreSQL encoding issue while executing query from command line

Make sure the client_encoding matches the encoding of your file. Check your system locale. Then use a matching command line argument for psql. Quoting the manual here:

If at least one of standard input or standard output are a terminal,
then psql sets the client encoding to "auto", which will detect the
appropriate client encoding from the locale settings (LC_CTYPE
environment variable on Unix systems). If this doesn't work out as
expected, the client encoding can be overridden using the environment
variable PGCLIENTENCODING.

Example for a Linux shell:

env PGCLIENTENCODING='WIN1258' psql DB_NAME -a -f QUERY_NAME.sql

List of available encodings in the manual.

Wrong characters in columns after executing SQL file from psql.exe

You have mistakenly set your client encoding to WIN1252 when you imported an UTF-8 encoded file.

Run the following on your command line before starting psql:

chcp 1252
set PGCLIENTENCODING=UTF8

If you want to view the data with psql, you will have to reset the client encoding to WIN1252.



Related Topics



Leave a reply



Submit