PostgreSQL:字符,其字节序为0xc2 0x81,编码为"UTF8".在编码"WIN1252"时没有等效的代码. [英] PostgreSQL: character with byte sequence 0xc2 0x81 in encoding "UTF8" has no equivalent in encoding "WIN1252"

查看:1031
本文介绍了PostgreSQL:字符,其字节序为0xc2 0x81,编码为"UTF8".在编码"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"

该行中的column之一包含日语字符,该日语字符已用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
  • 用日语字符更新行
  • connect to your database
  • set client_encoding to UTF8
  • update the row with Japanese characters

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

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

支持的字符集上查看文档.

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

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