GBase 8c
其他
文章

GBase 8c向表中插入数据(一)

发表于2023-12-06 16:55:58113次浏览0个评论

数据库DBCOMPATIBILITY设为兼容TD模式,且td_compatible_truncation参数设置为on的情况下,才会对超长字符串进行截断。

执行如下命令建立示例中需要使用的表table1、table2。

gbase=# CREATE TABLE table1(id int, a char(6), b varchar(6),c varchar(6));

gbase=# CREATE TABLE table2(id int, a char(20), b varchar(20),c varchar(20));

表1 客户端和服务端设置字符集的输出结果对比

编号

服务端字符集

客户端字符集

是否启用自动截断

示例

结果

说明

1

SQL_ ASCII

UTF8

gbase=#   INSERT INTO table1 VALUES(1,reverse('12 3AA

78'),reverse('123AA 78'),reverse('123AA 78'));

id |a|b|c

--+--+--+--

1 | 87| 87| 87

字符串在服务端翻转后,并进行截断,由于服务端和客户端的字符集不一致,字符A在客户端由多个字节表示,结果产生异常。

2

SQL_ ASCII

UTF8

gbase=#   INSERT INTO table1 VALUES(2,reverse('12

3A78'),reverse('123

A78'),reverse('123A

78'));

id |a|b|c

--+--+--+--

2 |873|873|873

字符串翻转后,又进行了自动截断,所以产生了非预期的效果。

3

SQL_ ASCII

UTF8

gbase=# INSERT INTO table1 VALUES(3,'87A 123','87A123','87A

123');

id | a | b| c

---+---+---+--

3 | 87A1 | 87

A1 | 87A1

字符串类型的字段长度是客户端字符编码长度的整数倍,所以截断后产生结果正常。

4

SQL_ ASCII

UTF8

gbase=#   INSERT INTO table2 VALUES(1,reverse('12

3AA

78'),reverse('123AA

78'),reverse('123AA

78'));

gbase=#

INSERT INTO table2

VALUES(2,reverse('12

3A78'),reverse('123

A78'),reverse('123A

78'));

id |a|b|c

---+-+--+--

1 |87|321| 87

321 | 87 321

2 | 87321|

87321| 87321

与示例1类似,多字节字符翻转之后不

评论

登录后才可以发表评论