Getting the below exception while executing SELECT
query for a particular row on that table
ERROR: character with byte sequence 0xc2 0x81 in en
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.
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!
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:
client_encoding
to UTF8To 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.
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.