无法在 Postgres 中插入德语字符 [英] Can not insert German characters in Postgres

查看:12
本文介绍了无法在 Postgres 中插入德语字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 UTF8 作为 Postgres 8.4.11 数据库的编码:

创建数据库测试WITH OWNER = postgres编码 = 'UTF8'表空间 = 我的数据LC_COLLATE = 'de_DE.UTF-8'LC_CTYPE = 'de_DE.UTF-8'连接限制 = -1;ALTER DATABASE test SET default_tablespace='mydata';ALTER DATABASE test SET temp_tablespaces=mydata;

以及l

的输出

 测试 |postgres |UTF8 |de_DE.UTF-8 |de_DE.UTF-8 |

当我尝试插入一个德语字符时:

create table x(a text);插入 x 值('ä,ß,ö');

<块引用>

错误:编码UTF8"的字节序列无效:0xe42cdf提示:如果字节序列与由client_encoding"控制的服务器预期的编码不匹配,也会发生此错误.

我正在使用 PuTTY 进行连接.有什么想法吗?

解决方案

关键元素是 client_encoding - 服务器期望从客户端获得的编码.它必须与实际发送的内容相匹配.show client_encoding 你能得到什么?是UNICODE吗?

自动字符集转换一章中阅读更多内容手册的服务器和客户端之间.

如果您使用 psql 作为客户端,您可以使用 encoding 设置 client_encoding.检查本地系统用户的编码(在 Linux 上,在 shell 中键入 locale)并在 psql 中设置匹配的 client_encoding.如果您在系统上使用与 PostgreSQL 服务器的 encoding 相同的语言环境,则可以避免这种复杂情况.

如果您使用 puTTY(在 Windows 上),请确保将其翻译"设置为因此.看看设置:窗口 - 翻译.必须匹配 client_encoding.您可以在正在运行的会话中右键单击并选择更改设置.您还可以将这些设置与保存的会话一起保存.

I am using UTF8 as encoding for my Postgres 8.4.11 database:

CREATE DATABASE test
  WITH OWNER = postgres
       ENCODING = 'UTF8'
       TABLESPACE = mydata
       LC_COLLATE = 'de_DE.UTF-8'
       LC_CTYPE = 'de_DE.UTF-8'
       CONNECTION LIMIT = -1;

ALTER DATABASE test SET default_tablespace='mydata';
ALTER DATABASE test SET temp_tablespaces=mydata;

And the output of l

 test | postgres  | UTF8     | de_DE.UTF-8 | de_DE.UTF-8 |

When I try to insert a German character:

create table x(a text);

insert into x values('ä,ß,ö');

ERROR:  invalid byte sequence for encoding "UTF8": 0xe42cdf
HINT:  This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".

I am using puTTY to connect. Any idea?

解决方案

The key element is the client_encoding - the encoding the server expects from your client. It has to match what is actually sent. What do you get for show client_encoding? Is it UNICODE?

Read more in the chapter Automatic Character Set Conversion Between Server and Client of the manual.

If you are using psql as client, you can set client_encoding with encoding. Check the encoding your local system users (on Linux type locale in the shell) and set a matching client_encoding in psql. You can avoid such complications if you use the same locale on your system as you use as encoding for your PostgreSQL server.

If you use puTTY (on Windows), make sure to set its "Translation" accordingly. Have a look at Settings: Window - Translation. Must match client_encoding. You can right-click in a running session and chose Change Settings. You can also save these settings with your saved sessions.

这篇关于无法在 Postgres 中插入德语字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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