PostgreSQL: character with byte sequence 0xc2 0x81 in encoding “UTF8” has no equivalent in encoding “WIN1252”

不打扰是莪最后的温柔 提交于 2020-06-22 11:39:50

问题


Getting the below exception while executing SELECT query for a particular row on that table

ERROR:  character with byte sequence 0xc2 0x81 in encoding "UTF8" has no equivalent in encoding "WIN1252"

One of the column in that row contains Japanese character which has been encoded with UTF-8 and inserted into it.

Is there any fix for this issue?


回答1:


You should know what encoding is used in your database.

SHOW server_encoding;

When you connect to your database you can specify what encoding should your client use:

SET client_encoding TO 'UTF8';

If server and client encoding differ, the database driver tries to translate between those two encoding. When it can not find an equivalent character, the error is thrown.

So server encoding and client encoding should be the same to avoid problems like yours.

To fix your problem:

  • connect to your database
  • set client_encoding to UTF8
  • update the row with Japanese characters

To avoid this problem in the future remember to set client_encoding to proper value when you connect to the database.

Check the documentation on Supported Character Sets.




回答2:


see here

I've encountered this error "ERROR: character with byte sequence <...> in encoding "UTF8" has no equivalent in encoding "WIN1252";" while using MySQL Workbench to migrate data from PostgreSQL to MySQL. I was not sure why this was happening because the target MySQL database had UTF8 encoding and I thought that everything can be mapped to it.

The real root cause of this problem turned out to be the PostgreSQL driver I used to connect to the source DB and specified in the Workbench which was PostgreSQL ODBC Driver (ANSI) and after I changed it to PostgreSQL ODBC Driver (UNICODE) everything worked fine.




回答3:


I got the error when Crystal Reports saw this set of characters in a field: [‎18/‎03/‎2019 2:20 PM]

In the end I just changed the content of that field, but unless I can find a decent PostgreSQL ODBC Driver that is designed for UTF8 I will probably see this issue pop up every few weeks, and will need to data cleanse.




回答4:


It happened with me in crystal reports...

I changed the content of the column of my view that was generating error...

I discovered that character "0xc2 0x81" is equal "chr(128)" - http://lwp.interglacial.com/appf_01.htm - so i've replaced this character, like this: (replace((mi.complemento)::text, chr(128), 'C'::text))::character varying(400) AS complemento

cheers!



来源:https://stackoverflow.com/questions/38481829/postgresql-character-with-byte-sequence-0xc2-0x81-in-encoding-utf8-has-no-equ

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!