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