一、概述
1、基于PostgreSQL数据敏感
openGauss源于PostgreSQL
PostgreSQL对数据大小写敏感:
1、PG中默认是大小写不敏感,表名、字段名等不区分大小写,大写字母会自动转换为小写字母,需要使用大写字母时需要使用双引号,或借助函数
2、查询数据中的大小写敏感
3、创建的账号或者角色大小写敏感
如果要指定表名或者列名为大写该怎么办?
只要加上双引号即可。
但是这种方法很麻烦,后续对于这个这些表或列进行相应的操作都需要带上双引号,不建议这样使用。
试验主要围绕这三点验证
openGauss试验结果:
1、数据库名、表名、列名创建都可以无符号创建和双引号创建
2、数据库名创建,无符号大小写库名、双引号小写库名创建后只能以全小写库名查询,双引号大写库名创建后只能原样查询
3、表名创建,无符号大小写表名、双引号小写表名创建后都可以使用无符号大小写、双引号小写查询
双引号大写表名创建后,只能使用双引号原样查询
4、列名创建,无符号大小写列名、双引号小写列名创建后都可以使用无符号大小写、双引号小写查询
双引号大写列名创建后,只能使用双引号原样查询
5、数据字符串插入和查询,只支持单引号
6、数据查询大小写敏感
二、试验
1、数据库名
1、符号试验
无符号、``、''、""
create database test1 owner joe; #OK
create database `test2` owner joe; #ERROR: syntax error at or near "`"
create database 'test3' owner joe; #ERROR: syntax error at or near "`"
create database "test4" owner joe; #OK
drop database test1;
drop database "test4";
2、数据库名大小写敏感验证
创建数据库
create database test1 owner joe;
create database TEST2 owner joe;
create database "test3" owner joe;
create database "TEST4" owner joe;
数据库查询
select datname from pg_database;
test1
test2
test3
TEST4 #除了冒号带大写字母的,其他的都变成了小写
select datname from pg_database where datname='test1'; #test1
select datname from pg_database where datname='TEST1'; #null
select datname from pg_database where datname='TEST2'; #null
select datname from pg_database where datname='test2'; #test2
select datname from pg_database where datname='test3'; #test3
select datname from pg_database where datname='TEST3'; #null
select datname from pg_database where datname='test4'; #null
select datname from pg_database where datname='TEST4'; #TEST4
清理数据库
drop database test1;
drop database test2;
drop database test3;
drop database "TEST4";
总结
无符号大写库名、无符号小写库名、双引号小写库名,创建后都会转换成无符号小写数据库名
双引号大写库名,创建后是无符号大写数据库名
2、表名
1、符号试验
无符号、``、''、""
create table test1(id int); #OK
create table `test2`(id int); #ERROR: syntax error at or near "`"
create table 'test3'(id int); #ERROR: syntax error at or near "'test3'"
create table "test4"(id int); #OK
drop table test1;
drop table "test4";
2、表名大小写敏感验证
create table test1(id int);
create table TEST2(id int);
create table "test3"(id int);
create table "TEST4"(id int);
表查询
select * from test1; #OK
select * from TEST1; #OK
select * from "test1"; #OK
select * from "TEST1"; #ERROR: relation "TEST1" does not exist on dn_6001
select * from test2; #OK
select * from TEST2; #OK
select * from "test2"; #OK
select * from "TEST2"; #ERROR: relation "TEST2" does not exist on dn_6001
select * from test3; #OK
select * from TEST3; #OK
select * from "test3"; #OK
select * from "TEST3"; #ERROR: relation "TEST3" does not exist on dn_6001
select * from test4; #ERROR: relation "test4" does not exist on dn_6001
select * from TEST4; #ERROR: relation "test4" does not exist on dn_6001
select * from "test4"; #ERROR: relation "test4" does not exist on dn_6001
select * from "TEST4"; #OK
表清理
drop table test1;
drop table TEST2;
drop table "test3";
drop table "TEST4";
总结:无符号的表名,无符号大写、无符号小写、双引号小写,都可以查询,双引号大写无法查询
有双引号小写的表名,无符号大写、无符号小写、双引号小写,都可以查询,双引号大写无法查询
有双引号大写的表名,无符号大写、无符号小写、双引号小写,无法查询,双引号原样可以查询
3、列名
1、符号试验
无符号、``、''、""
create table test1(id int); #OK
create table test2(`id` int); #ERROR: syntax error at or near "`"
create table test3('id' int); #ERROR: syntax error at or near "'id'"
create table test4("id" int); #OK
drop table if exists test1;
drop table if exists test4;
总结:列名支持无符号和双引号("")
2、列名大小写敏感验证
创建表并插入数据
create table test1(id1 int,ID2 int,"id3" int,"ID4" int);
insert into test1 values(1,2,3,4),(5,6,7,8);
数据查询
第一步
select id1 from test1 where id1=1; #1
select id1 from test1 where ID1=1; #1
select id1 from test1 where "id1"=1; #1
select id1 from test1 where "ID1"=1; #ERROR: column "ID1" does not exist
第二步
select id1 from test1 where id2=2; #1
select id1 from test1 where ID2=2; #1
select id1 from test1 where "id2"=2; #1
select id1 from test1 where "ID2"=2; #ERROR: column "ID2" does not exist
第三步
select id1 from test1 where id3=3; #1
select id1 from test1 where ID3=3; #1
select id1 from test1 where "id3"=3; #1
select id1 from test1 where "ID3"=3; #ERROR: column "ID3" does not exist
第四步
select id1 from test1 where id4=4; #ERROR: column "id4" does not exist
select id1 from test1 where ID4=4; #ERROR: column "id4" does not exist
select id1 from test1 where "id4"=4; #ERROR: column "id4" does not exist
select id1 from test1 where "ID4"=4; #1
数据清理
drop table if exists test1;
总结:无符号的列名,无符号大写、无符号小写、双引号小写,都可以查询,双引号大写无法查询
有双引号小写的列名,无符号大写、无符号小写、双引号小写,都可以查询,双引号大写无法查询
有双引号大写的列名,无符号大写、无符号小写、双引号小写,无法查询,双引号大写可以查询
4、数据大小写敏感
1、符号试验
无符号、``、''、""
create table test1(id int,name VARCHAR(10));
insert into test1 values(1,hello); #ERROR: column "hello" does not exist
insert into test1 values(2,`hello`); #ERROR: column "hello" does not exist
insert into test1 values(3,'hello'); #OK
insert into test1 values(4,"hello"); #ERROR: column "hello" does not exist
总结:具体数据字符串类型只支持单引号('')
2、数据大小写敏感验证
数据插入
delete from test1
insert into test1 values(1,'hello');
insert into test1 values(2,'HEllo');
insert into test1 values(3,'HELLO');
数据查询
select id from test1 where name='hello'; #1
select id from test1 where name='HEllo'; #2
select id from test1 where name='HELLO'; #3
select id from test1 where name like 'HE%'; #2、3
清理数据
drop table if exists test1;
总结:数据大小写敏感
服务器租用托管,机房租用托管,主机租用托管,https://www.e1idc.com