创建UTF8字符集的数据表
create database test_utf8 encoding ='UTF8';
\c test_utf8
create table test_utf8(id int,name varchar(10));
确认表的字符集为UTF8
\l test_utf8
--对test_utf8数据表写入中文数据;
\c test_utf8
insert into test_utf8 values(1,'中国');
--查询写入数据,预期无乱码
\c test_utf8
select * from test_utf8;
--清除环境
\c test
drop database test_utf8;
创建GBK字符集的数据表
CREATE DATABASE test_gbk WITH ENCODING 'GBK' LC_COLLATE='zh_CN.GBK' LC_CTYPE='zh_CN.GBK' TEMPLATE template0;
\c test_gbk
create table test_gbk(id int,name varchar(10));
确认表的字符集为GBK
\l test_gbk
--对test_gbk数据表写入中文数据;
\c test_gbk
insert into test_gbk values(1,'中国');
--查询写入数据,预期无乱码。
\c test_gbk
select * from test_gbk;
--清除环境
\c test
drop database test_gbk;
创建GB18030字符集的数据表
CREATE DATABASE test_GB18030 WITH ENCODING 'GB18030' LC_COLLATE='zh_CN.GB18030' LC_CTYPE='zh_CN.GB18030' TEMPLATE template0;
\c test_gb18030
create table test_GB18030(id int,name varchar(10));
确认表的字符集为gb18030
\l test_gb18030
--对test_GB18030数据表写入中文数据;
\c test_GB18030
insert into test_GB18030 values(1,'中国');
--查询写入数据,预期无乱码。
\c test_gb18030
select * from test_GB18030;
--清除环境
\c test
drop database test_gb18030;