无法在Postgres中插入德语字符

bab*_*oso 1 postgresql encoding text utf-8

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

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;
Run Code Online (Sandbox Code Playgroud)

和输出 \l

 test | postgres  | UTF8     | de_DE.UTF-8 | de_DE.UTF-8 |
Run Code Online (Sandbox Code Playgroud)

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

create table x(a text);

insert into x values('ä,ß,ö');
Run Code Online (Sandbox Code Playgroud)
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".
Run Code Online (Sandbox Code Playgroud)

我正在使用puTTY进行连接.任何的想法?

Erw*_*ter 5

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

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

如果您使用psql作为客户端,则可以client_encoding使用\encoding.检查本地系统用户的编码(在localeshell中的Linux类型上)并client_encoding在psql中设置匹配.如果在系统上使用与encodingPostgreSQL服务器相同的区域设置,则可以避免此类复杂情况.

如果您使用puTTY(在Windows上),请确保相应地设置其"翻译".看看设置:窗口 - 翻译.必须匹配client_encoding.您可以在正在运行的会话中右键单击,然后选择" 更改设置".您还可以使用已保存的会话保存这些设置.

我有"UTF-8"腻子Windows XP系统上,encoding并且client_encoding所有设置UNICODE(= UTF8Postgres里),我的作品.