PostgreSQL:编码“UTF8”中字节序列为 0xc2 0x81 的字符在编码“WIN1252”中没有等效项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38481829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PostgreSQL: character with byte sequence 0xc2 0x81 in encoding "UTF8" has no equivalent in encoding "WIN1252"
提问by Raamesh Keerthi
Getting the below exception while executing SELECT
query for a particular row on that table
SELECT
在对该表上的特定行执行查询时出现以下异常
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.
之一的column
该行中包含已编码的UTF-8,并插入到它的日文字符。
Is there any fix for this issue?
这个问题有什么解决办法吗?
回答by Adam
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
- 连接到您的数据库
- 设置
client_encoding
为 UTF8 - 用日语字符更新行
To avoid this problem in the future remember to set client_encoding
to proper value when you connect to the database.
为避免将来出现此问题,请记住client_encoding
在连接到数据库时设置为正确的值。
Check the documentation on Supported Character Sets.
查看有关支持的字符集的文档。
回答by Jake
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.
我遇到了这个错误“错误:编码“UTF8”中的字节序列<...>的字符在编码“WIN1252”中没有等价物;” 同时使用 MySQL Workbench 将数据从 PostgreSQL 迁移到 MySQL。我不确定为什么会发生这种情况,因为目标 MySQL 数据库具有 UTF8 编码,我认为一切都可以映射到它。
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.
这个问题的真正根本原因原来是我用来连接到源数据库并在工作台中指定的 PostgreSQL 驱动程序,它是 PostgreSQL ODBC 驱动程序(ANSI),在我将其更改为 PostgreSQL ODBC 驱动程序(UNICODE)后,一切正常.
回答by Chillywinter
I got the error when Crystal Reports saw this set of characters in a field: [?18/?03/?2019 2:20 PM]
当 Crystal Reports 在字段中看到这组字符时出现错误:[?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.
最后,我只是更改了该字段的内容,但除非我能找到一个为 UTF8 设计的不错的 PostgreSQL ODBC 驱动程序,否则我可能每隔几周就会看到这个问题,并且需要进行数据清理。
回答by Fernando Meneses Gomes
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
我发现字符 "0xc2 0x81" 等于 "chr(128)" - http://lwp.interglacial.com/appf_01.htm- 所以我已经替换了这个字符,就像这样:(replace((mi.complemento) ::text, chr(128), 'C'::text))::character variables (400) AS 补码
cheers!
干杯!