LightDB23.4 GBK和UTF8转码失败的字符替换成空格

背景介绍

用户使用迁移工具从Oracle数据库迁移数据到LightDB的过程中发现,某些GBK编码转成UTF8编码后,在插入到LightDB中会报错。以GBK编码AAA1为例,LightDB的GBK和UTF8映射表中不支持AAA1这个GBK编码的转换。不支持的GBK编码都是处于GBK编码的自定义区间。

在上图中,UTF8编码EE8080对应于GBK编码AAA1,插入到LightDB时报错。

所以,在LightDB23.4中,将GBK和UTF8转码失败的字符替换成空格。只有在客户端和服务端编码不一致,且需要GBK和UTF8之间转码的时候,这个功能才生效。

功能示例

客户端编码GBK,服务端编码UTF8
  1. 建表,插入数据
powershell 复制代码
lightdb@postgres=# \c lt_test
You are now connected to database "lt_test" as user "lightdb".
compatible type: postgresql
lightdb@lt_test=# 
lightdb@lt_test=# 
lightdb@lt_test=# create table t1(cont text);
CREATE TABLE
lightdb@lt_test=# 
lightdb@lt_test=# 
lightdb@lt_test=# show server_encoding ;
 server_encoding 
-----------------
 UTF8
(1 row)

lightdb@lt_test=# 
lightdb@lt_test=# \encoding gbk
lightdb@lt_test=# 
lightdb@lt_test=# \i gbk.test 
INSERT 0 1
lightdb@lt_test=# 
lightdb@lt_test=# select * from t1;
 cont  
-------
 我 们
(1 row)

lightdb@lt_test=# select oid,datname from pg_database where datname = 'lt_test';
  oid  | datname 
-------+---------
 25485 | lt_test
(1 row)

lightdb@lt_test=# 
lightdb@lt_test=# select oid,relfilenode from pg_class where relname = 't1';
  oid  | relfilenode 
-------+-------------
 25486 |       25486
(1 row)

lightdb@lt_test=# checkpoint ;
CHECKPOINT
lightdb@lt_test=# 
lightdb@lt_test=# select oid,relfilenode from pg_class where relname = 't1';
  oid  | relfilenode 
-------+-------------
 25486 |       25486
(1 row)

lightdb@lt_test=# 
  1. gbk.test文件中的内容

  2. 查看实际表文件中的数据, e6 88 91 20 e4 bb ace6 88 91表示我,e4 bb ac表示们,中间的20就是转换后的空格

powershell 复制代码
[lightdb@localhost 25485]$ hexdump -C 25486
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00002000
[lightdb@localhost 25485]$ hexdump -C 25486
00000000  00 00 00 00 f0 a9 0c 22  00 00 00 00 1c 00 e0 1f  |......."........|
00000010  00 20 04 20 00 00 00 00  e0 9f 40 00 00 00 00 00  |. . ......@.....|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00001fe0  07 05 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00001ff0  01 00 01 00 02 09 18 00  11 e6 88 91 20 e4 bb ac  |............ ...|
00002000
[lightdb@localhost 25485]$ 
相关推荐
tudficdew16 分钟前
实战:用Python分析某电商销售数据
jvm·数据库·python
sjjhd65238 分钟前
Python日志记录(Logging)最佳实践
jvm·数据库·python
Configure-Handler43 分钟前
buildroot System configuration
java·服务器·数据库
2301_821369611 小时前
用Python生成艺术:分形与算法绘图
jvm·数据库·python
电商API_180079052472 小时前
第三方淘宝商品详情 API 全维度调用指南:从技术对接到生产落地
java·大数据·前端·数据库·人工智能·网络爬虫
2401_832131952 小时前
Python单元测试(unittest)实战指南
jvm·数据库·python
打工的小王3 小时前
redis(四)搭建哨兵模式:一主二从三哨兵
数据库·redis·缓存
Anarkh_Lee3 小时前
【小白也能实现智能问数智能体】使用开源的universal-db-mcp在coze中实现问数 AskDB智能体
数据库·人工智能·ai·开源·ai编程
橘子133 小时前
MySQL用户管理(十三)
数据库·mysql
Dxy12393102163 小时前
MySQL如何加唯一索引
android·数据库·mysql