我尝试从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);
我得到了这样的答复:
ERROR: column "fk_numbers_id" does not exist LINE 1: ...m from main_sim sim left join main_number num on (FK_Numbers...
但如果我只是用以下方式检查我的桌子:
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
...因为我们可以看到该列存在。
可能是它的语法错误,但我无法看到...
任何帮助都将受到赞赏。 Alessio的
答案 0 :(得分:18)
不,列FK_Numbers_id
不存在,只有列"FK_Numbers_id"
存在
显然,您使用双引号创建了表格,因此所有列名称现在都区分大小写,您必须始终使用双引号:
select sim.id as idsim,
num.id as idnum
from main_sim sim
left join main_number num on ("FK_Numbers_id" = num.id);
重温已经documented in the manual的内容:
列foo
和FOO
相同,列"foo"
和"FOO"
不相同。