pgsql中变量不区分大小写,关键字一般采用大写,是为了和变量进行区分,然而变量值是区分大小写的
举例1
pg_class 表存储着数据库中已有的表,而pg_class的relname字段值是区分大小写的。
例如:检索数据库中某个表是否存在,不存则新建该表,存在则清空该表,pgsql语言如下:
select count(*) from pg_class where relname='crime_central'
返回结果:
count
-------
1
(1 row)
relname字段值使用大写(CRIME_central),则
select count(*) from pg_class where relname='CRIME_central';
返回结果:
count
-------
0
(1 row)
但是,在创建新表的时候,是不区分大小写的,例如:
gps=# create table WW(id integer);
CREATE TABLE
gps=# create table ww(id integer);
ERROR: relation "ww" already exists
总结:
同样是表名,创建表时,表名不区分大小写,而表名作为变量的值而存在时,区分大小写;
举例2
变量值区分大小写,如作为主键字段的值
gps=# create table ww(id varchar,primary key(id));
CREATE TABLE
gps=# insert into ww values('OO');
INSERT 0 1
gps=# insert into ww values('oo');
INSERT 0 1
gps=# insert into ww values('oo');
ERROR: duplicate key value violates unique constraint "ww_pkey"
DETAIL: Key (id)=(oo) already exists.
gps=# insert into ww values('Oo');
INSERT 0 1
gps=# select * from ww;
id
----
OO
oo
Oo