Postgres:关系不存在错误

Ayu*_*uru 18 postgresql quoted-identifier

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

sudo -u arajguru psql dump

select current_user;
 current_user 
--------------
 arajguru
Run Code Online (Sandbox Code Playgroud)

现在我能够看到所有新创建的表:

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)
Run Code Online (Sandbox Code Playgroud)

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

dump=> select * from Approvals;
ERROR:  relation "approvals" does not exist
LINE 1: select * from Approvals;
Run Code Online (Sandbox Code Playgroud)

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

a_h*_*ame 31

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

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

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

select * 
from "Approvals";
Run Code Online (Sandbox Code Playgroud)

作为一般建议:永远不要在 SQL 中使用双引号

  • @AyushiRajguru:因为“表格列表”以大写/小写字母显示它们。实现这一点的唯一方法是使用双引号(如[手册中记录的](https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS) ) (2认同)