不能在postgres中删除表

Ted*_*son 10 postgresql

我是postgresql的新手,我似乎无法让它丢掉一张桌子.

db_dev=# \dt
          List of relations
 Schema |    Name     | Type  | Owner
--------+-------------+-------+-------
 public | DataSources | table | ted
 public | Emails      | table | ted
 public | Users       | table | ted
(3 rows)
Run Code Online (Sandbox Code Playgroud)

当我尝试删除users表时,它会出错:

db_dev=# drop table Users;
ERROR:  table "users" does not exist
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

gsi*_*ems 23

问题是您的Users表是大小写混合的(Postgres中的对象名称区分大小写).如果没有表格名称,Postgres会将提供的名称折叠为"用户" - 这是不存在的.引用表名的解决方案有效,不是因为用户是保留名称,而是因为通过引用它告诉Postgres删除"Users"表而不是"users"表.


小智 6

看来你做得对,但你可以尝试这样做:

DROP TABLE IF EXISTS Users;
Run Code Online (Sandbox Code Playgroud)

或这个:

DROP TABLE IF EXISTS Public.Users;
Run Code Online (Sandbox Code Playgroud)

如果存在就删除,如果不存在你就会知道。