磨砺技术珠矶,践行数据之道,追求卓越价值
回到上一级页面:PostgreSQL基础知识与基本操作索引页    回到顶级页面:PostgreSQL索引页[作者 高健@博客园  [email protected]]

实验过程如下、建表:

建立带引号的表名:

postgres=# create table "GaoUser"(name varchar(10),age integer);
CREATE TABLE
postgres=# select * from GaoUser;
ERROR: relation "gaouser" does not exist
LINE 1: select * from GaoUser;
^
postgres=# select * from gaouser;
ERROR: relation "gaouser" does not exist
LINE 1: select * from gaouser;
^
postgres=# select * from "GaoUser";
name | age
------+-----
(0 rows)

上述的过程表明,带引号的表和不带引号的表,不是一回事。

再进一步实验:

postgres=# create table GaoUser(name varchar(10),age integer);
CREATE TABLE
postgres=# postgres=# create table gaouser(name varchar(10),age integer);
ERROR: relation "gaouser" already exists
postgres=# postgres=# create table GAOUSER(name varchar(10),age integer);
ERROR: relation "gaouser" already exists
postgres=# postgres=# select * from GaoUser;
name | age
------+-----
(0 rows) postgres=# select * from gaouser;
name | age
------+-----
(0 rows) postgres=#

这说明,不带引号的表名,无论大写还是小写,都是一回事。

进一步的实验,可以验证此看法。

postgres=# insert into GaoUser values('user001',25);
INSERT 0 1
postgres=# insert into "GaoUser" values('user002',40);
INSERT 0 1
postgres=# select * from GaoUser;
name | age
---------+-----
user001 | 25
(1 row) postgres=# select * from gaouser;
name | age
---------+-----
user001 | 25
(1 row) postgres=# postgres=# select * from "GaoUser";
name | age
---------+-----
user002 | 40
(1 row)
postgres=# insert into GaoUser values('User003',27);
INSERT 0 1
postgres=# select * from GaoUser;
name | age
---------+-----
user001 | 25
User003 | 27
(2 rows) postgres=# insert into "GaoUser" values('User004',42);
INSERT 0 1
postgres=# select * from "GaoUser";
name | age
---------+-----
user002 | 40
User004 | 42
(2 rows) postgres=#

[作者 高健@博客园  [email protected]]
回到上一级页面:PostgreSQL基础知识与基本操作索引页    回到顶级页面:PostgreSQL索引页磨砺技术珠矶,践行数据之道,追求卓越价值

05-11 21:59