Postgres:关系不存在错误


14

我用pg_restore用转储文件加载了我的postgres数据库。我用用户连接到数据库:

sudo -u arajguru psql dump

select current_user;
 current_user 
--------------
 arajguru

现在,我可以看到所有新创建的表:

dump=> \dt
               List of relations
 Schema |       Name        | Type  |  Owner   
--------+-------------------+-------+----------
 public | Approvals         | table | arajguru
 public | Approvers         | table | arajguru
 public | Conditions        | table | arajguru
 public | Entities          | table | arajguru
 public | EntityDefinitions | table | arajguru
 public | Projects          | table | arajguru
 public | Rules             | table | arajguru
 public | run_history       | table | arajguru
(8 rows)

但是,当我尝试触发select *查询时,它给了我这个错误:

dump=> select * from Approvals;
ERROR:  relation "approvals" does not exist
LINE 1: select * from Approvals;

此错误的原因可能是什么?请帮忙。

Answers:


24

您用双引号创建了表,现在名称区分大小写。

如手册中所述 "Approvals"Approvals是两个不同的名称。

现在,您以区分大小写的方式创建了表名,您必须始终使用那些可怕的双引号。

select * 
from "Approvals";

作为一般建议:切勿在SQL中使用双引号


1
谢谢!现在工作。您怎么知道这些表是用双引号创建的?
Ayushi Rajguru

1
@AyushiRajguru:因为“表列表”以大写/小写形式显示它们。实现此目标的唯一方法是使用双引号(如 手册中所述
a_horse_with_no_name

啊,我对原木与“原木”的看法相同谢谢youuuuu <3
csomakk
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.