SQL sql语句错误:“列..不存在”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10015531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sql statement error: "column .. does not exist"
提问by Alessio
Im trying from postgres console this command:
我从 postgres 控制台尝试这个命令:
select sim.id as idsim,
num.id as idnum
from main_sim sim
left join main_number num on (FK_Numbers_id=num.id);
and I've got this response:
我得到了这样的回应:
ERROR: column "fk_numbers_id" does not exist LINE 1: ...m from main_sim sim left join main_number num on (FK_Numbers...
but if I simply check my table with:
但如果我只是检查我的表:
dbMobile=# \d main_sim
id | integer | not null default
Iccid | character varying(19) | not null
...
FK_Device_id | integer |
FK_Numbers_id | integer |
Indexes:
"main_sim_pkey" PRIMARY KEY, btree (id)
"main_sim_FK_Numbers_id_key" UNIQUE, btree ("FK_Numbers_id")
"main_sim_Iccid_key" UNIQUE, btree ("Iccid")
"main_sim_FK_Device_id" btree ("FK_Device_id")
Foreign-key constraints:
"FK_Device_id_refs_id_480a73d1" FOREIGN KEY ("FK_Device_id") REFERENCES main_device(id) DEFERRABLE INITIALLY DEFERRED
"FK_Numbers_id_refs_id_380cb036" FOREIGN KEY ("FK_Numbers_id") REFERENCES main_number(id) DEFERRABLE INITIALLY DEFERRED
...as we can see the column exist.
...正如我们可以看到的列存在。
probably it's syntax error, but I'm unable to see what...
可能是语法错误,但我看不到什么......
any help will'be appreciated. Alessio
任何帮助将不胜感激。阿莱西奥
回答by a_horse_with_no_name
No, the column FK_Numbers_id
does not exist, only a column "FK_Numbers_id"
exists
不,该列FK_Numbers_id
不存在,只有一列"FK_Numbers_id"
存在
Apparently you created the table using double quotes and therefor all column names are now case-sensitive and you have to use double quotes all the time:
显然,您使用双引号创建了表,因此所有列名现在都区分大小写,您必须始终使用双引号:
select sim.id as idsim,
num.id as idnum
from main_sim sim
left join main_number num on ("FK_Numbers_id" = num.id);
To recap what is already documented in the manual:
The column foo
and FOO
are identical, the columns "foo"
and "FOO"
are not.
列foo
和FOO
相同,列"foo"
和"FOO"
不相同。