Tuesday, January 16, 2018

Command psql of PostgreSQL Complains about Encoding

I have a PostgreSQL database instance configured to use UTF-8. When I connects to it using psql on Windows, it complains with the following,

foopgdb => select * from bar;
ERROR:  character with byte sequence 0xe2 0x86 0x92 in encoding "UTF8" has no 
equivalent in encoding "WIN1252"
foopgdb =>

Method 1

It turns out that we can inform psql the encoding and select proper encoding table when we run psql as follows in a Windows Command Prompt window,

chcp 65001

The explanation about PGCLIENTENCODING is in the PostgreSQL documentation while that of chcp at Microsoft Technet. The reference to the code page 65001 is at this MSDN page.

However, the above method may result in the Not enough memory error on some version of Windows, such as, Windows 7. See this discussion for more.

Method 2

We can also set the encoding in psql as follows,

foopgdb => \encoding UTF8
foopgdb => select * from bar;
foopgdb =>

1 comment:

  1. How to Solve Postgres Database Encoding Problem? Contact to Postgres SQL Support for Linux

    Rapidly look at your Postgres database encoding issue with Cognegic's Postgres SQL Support for Windows or PostgreSQL Relational Database Service. The central furthest traverses of Postgres is to store information customarily yet once this encoding issue is rise then it pushes toward convincing the opportunity to be to deal with your Postgres condition. To pick this issue we give strong help which is under in your fiscal game plan. Thusly, oversee contact to our particular administrators and look at the actuate bolster.

    For More Info: https://cognegicsystems.com/
    Contact Number: 1-800-450-8670
    Email Address- info@cognegicsystems.com
    Company’s Address- 507 Copper Square Drive Bethel Connecticut (USA) 06801