所以我在线阅读教程,在进行常规查询时,我的数据库出现了一个奇怪的问题。所以我看到以下内容不起作用:
select * from DBS
ERROR: relation "dbs" does not exist
但这有效:
select * from "DBS"
当我这样做时,它失败了:
select name from "DBS"
ERROR: column "name" does not exist
但这可行,但实际上并没有返回正确的信息(它只有每一行的名称:
select 'name' from "DBS"
name
name
name
Postgres上有一些设置会导致这种情况发生吗? Postgres 9.4.5(在RDS上)。
select 'NAME' from "DBS";
?column?
----------
NAME
NAME
NAME
(3 rows)
当我从“DBS”看select *时;
NAME
----------
default
matt
matt2
答案 0 :(得分:4)
您需要在表标识符周围指定引号,因为该表使用大写字母并使用引号创建。
postgres has some distinctive behavior re: quoting
select 'name' from "DBS"
您只需为表格中的每一行选择一次字符串文字'name'。
答案 1 :(得分:2)
Postgres is a little unique in that it folds everything to lowercase unless you use " quotes. I suspect you created your database using pgadmin. If you create a database in pgadmin using UPPER case it will create it with UPPER case and then you will be required to use " around the name to access it. Candidly I'd rename the db to lower case and get rid of the quotes, your life will be a lot easier.