背景介绍
LightDB在23.3版本之前仅客户端支持GBK/GB18030编码。在23.3版本中,LightDB服务端支持了GBK/GB18030编码格式存储数据,并且将支持的GB18030标准升级到了2022版。
服务端和客户端对应的编码格式如下表。
服务端编码 | 支持的客户端编码 |
---|---|
GBK | GBK, UTF-8 |
GB18030 | GB18030, UTF-8 |
如果在GBK/GB18030编码中含有0x40–0x7E这些特殊值,则不可以使用这些汉字去命名database、schema、relation和column。
使用说明
- 创建GBK/GB18030数据库。
lightdb@postgres=# create database gbktest encoding='gbk' locale='zh_CN.gbk' template template0;
CREATE DATABASE
lightdb@postgres=# create database gb18030test encoding='gb18030' locale='zh_CN.gb18030' template template0;
CREATE DATABASE
lightdb@postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+---------+----------+---------------+---------------+---------------------
gb18030test | lightdb | GB18030 | zh_CN.gb18030 | zh_CN.gb18030 |
gbktest | lightdb | GBK | zh_CN.gbk | zh_CN.gbk |
lt_test | lightdb | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |
postgres | lightdb | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 |
template0 | lightdb | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/lightdb +
| | | | | lightdb=CTc/lightdb
template1 | lightdb | UTF8 | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/lightdb +
| | | | | lightdb=CTc/lightdb
(6 rows)
lightdb@postgres=#
- 连接到数据库,查看数据库编码;
lightdb@postgres=# \c gb18030test
You are now connected to database "gb18030test" as user "lightdb".
lightdb@gb18030test=# show server_encoding ;
server_encoding
-----------------
GB18030
(1 row)
lightdb@gb18030test=# \c gbktest
You are now connected to database "gbktest" as user "lightdb".
lightdb@gbktest=# show server_encoding ;
server_encoding
-----------------
GBK
(1 row)
lightdb@gbktest=#
- 可以像其他数据库一样正常使用。
lightdb@gbktest=# create table t1(id int, addr text);
CREATE TABLE
lightdb@gbktest=# \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+---------
public | t1 | table | lightdb
(1 row)
lightdb@gbktest=# \c gb18030test
You are now connected to database "gb18030test" as user "lightdb".
lightdb@gb18030test=# create table t1(id int, addr text);
CREATE TABLE
lightdb@gb18030test=# \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+---------
public | t1 | table | lightdb
(1 row)
lightdb@gb18030test=#