Postgresql中表名、列名、用户名大小写问题

原文: https://blog.csdn.net/pg_hgdb/article/details/79227237

注意:是双引号,单引号可能会被解析成普通字符,因而是不识别的字段

highgo=# create table "ExChange" (id int);
CREATE TABLE
highgo=# create table ExChange (id int);
CREATE TABLE
highgo=# \d
             List of relations
     Schema     |   Name   | Type  | Owner
----------------+----------+-------+--------
 oracle_catalog | dual     | view  | highgo
 public         | ExChange | table | highgo
 public         | exchange | table | highgo
 public         | myt      | table | highgo
 public         | t1       | table | highgo
 public         | tran     | table | highgo
(6 rows)



highgo=# insert into exchange values (1);
INSERT 0 1
highgo=# insert into "ExChange" values (2);
INSERT 0 1

highgo=# select * FROM exchange ;
 id
----
  1
(1 row)
highgo=# select * FROM ExChange ;
 id
----
  1
(1 row)

highgo=# select * FROM "ExChange" ;
 id
----
  2
(1 row)


highgo=# insert into ExChange values (2);
INSERT 0 1
highgo=# select * FROM "ExChange" ;
 id
----
  2
(1 row)

highgo=# select * FROM exchange ;
 id
----
  1
  2
(2 rows)


> 从上面可以看出,如果不加双引号,那么表名都会被转化为小写。如果想要大小写混用,需要添加双引号。



highgo=# create table exchange (ID int,id int);
ERROR:  42701: column "id" specified more than once
highgo=# create table exchange (ID int,name text);
CREATE TABLE
highgo=# select id  from exchange ;
 id
----
(0 rows)

highgo=# select ID  from exchange ;
 id
----
(0 rows)

highgo=# select "ID"  from exchange ;
ERROR:  42703: column "ID" does not exist
LINE 1: select "ID"  from exchange ;

highgo=# \d exchange
   Table "public.exchange"
 Column |  Type   | Modifiers
--------+---------+-----------
 id     | integer |
 name   | text    |



highgo=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 aaa       |                                                            | {}
 gpadmin   | Superuser, Create role, Create DB                          | {}
 highgo    | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 replica   | Replication                                                | {}

highgo=# create table AAA;
ERROR:  42601: syntax error at or near ";"
LINE 1: create table AAA;
                        ^
highgo=# create user  AAA;
ERROR:  42710: role "aaa" already exists
highgo=# create user "AAA";
CREATE ROLE
highgo=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of
-----------+------------------------------------------------------------+-----------
 AAA       |                                                            | {}
 aaa       |                                                            | {}
 gpadmin   | Superuser, Create role, Create DB                          | {}
 highgo    | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
 replica   | Replication                                                | {}

实验证明,字段与用户同样会被自动转化为小写,除非添加双引号。 其实最好的办法就是全部用小写,这样才能尽量减少问题的出现。


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值