PostgreSQL:编码为“UTF8"的字节序列为 0xc2 0x81 的字符;在编码“WIN1252"方面没有等价物. [英] PostgreSQL: character with byte sequence 0xc2 0x81 in encoding "UTF8" has no equivalent in encoding "WIN1252"

查看:24
本文介绍了PostgreSQL:编码为“UTF8"的字节序列为 0xc2 0x81 的字符;在编码“WIN1252"方面没有等价物.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在对该表上的特定行执行 SELECT 查询时出现以下异常

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"

该行中的 之一包含已使用 UTF-8 编码并插入其中的日语字符.

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?

推荐答案

你应该知道你的数据库使用了什么编码.

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.

要解决您的问题:

  • 连接到您的数据库
  • 设置 client_encoding 为 UTF8
  • 用日语字符更新行

为避免将来出现此问题,请记住在连接到数据库时将 client_encoding 设置为正确的值.

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

查看有关支持的字符集的文档.

这篇关于PostgreSQL:编码为“UTF8"的字节序列为 0xc2 0x81 的字符;在编码“WIN1252"方面没有等价物.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆