postgresql/lightdb ERROR: invalid byte sequence for encoding "UTF8": 0xc92c与bytea类型

复制代码
zjh@postgres=# show %enc%;
                      name                       | setting |                                      description                                       
-------------------------------------------------+---------+----------------------------------------------------------------------------------------
 client_encoding                                 | UTF8    | Sets the client's character set encoding.
 server_encoding                                 | UTF8    | Sets the server (database) character set encoding.
(2 rows)

zjh@postgres=# select cast('序列'as bytea);
ERROR:  invalid byte sequence for encoding "UTF8": 0xd0 0xf2
复制代码

[zjh@hs-10-20-30-193 ~]$ echo $LANG
en_US.UTF8

复制代码
[zjh@hs-10-20-30-193 ~]$ locale
LANG=en_US.UTF8
LC_CTYPE="en_US.UTF8"
LC_NUMERIC="en_US.UTF8"
LC_TIME="en_US.UTF8"
LC_COLLATE="en_US.UTF8"
LC_MONETARY="en_US.UTF8"
LC_MESSAGES="en_US.UTF8"
LC_PAPER="en_US.UTF8"
LC_NAME="en_US.UTF8"
LC_ADDRESS="en_US.UTF8"
LC_TELEPHONE="en_US.UTF8"
LC_MEASUREMENT="en_US.UTF8"
LC_IDENTIFICATION="en_US.UTF8"
LC_ALL=
复制代码

jdbc端没有问题

insert into departments(bytetype) values(cast('序列' as bytea));

zjh@postgres=# select bytetype from departments where bytetype is not null;
bytetype
----------------
\xe5ba8fe58897
(1 row)

改用GBK字符集。

[zjh@hs-10-20-30-193 ~]$ export LANG="zh_CN.GBK"
[zjh@hs-10-20-30-193 ~]$ ltsql -p25432
ltsql (13.3-22.1)
Type "help" for help.

zjh@postgres=# select cast('序列'as bytea);
bytea
----------------
\xe5ba8fe58897
(1 row)

除了使用cast函数外,lightdb还支持'\十六进制', E'\\xNN'。如下:

INSERT INTO tab_bytea VALUES('\134',E'\\xFC');

参见:https://www.cnblogs.com/zhjh256/p/15518146.html  linux本地化与国际化(宽字符、编码格式、字符集)

https://www.cnblogs.com/zhjh256/p/6351266.html   c++中的字符集与中文(宽字符) 

如果是ltsql执行sql文件出现编码问题,可见https://www.cnblogs.com/zhjh256/p/15404475.html

https://www.zhangshengrong.com/p/4yNqjV7bXA/

posted @   zhjh256  阅读(322)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示