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)
参见:https://www.cnblogs.com/zhjh256/p/15518146.html
https://www.cnblogs.com/zhjh256/p/6351266.html
如果是ltsql执行sql文件出现编码问题,可见https://www.cnblogs.com/zhjh256/p/15404475.html。