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 @ 2022-05-04 10:23  zhjh256  阅读(285)  评论(0编辑  收藏  举报