SQL语句错误:“列..不存在”SQL语句错误:“列..不存在”(sql statement err

2019-05-13 11:09发布

我可是从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

......我们可以看到该列中存在。

也许它的语法错误,但我看不到有什么...

任何帮助将不胜感激。 阿莱西奥

Answer 1:

不,列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);

要回顾一下已经在手册中记载 :

fooFOO是相同的,列"foo""FOO"则不是。



文章来源: sql statement error: “column .. does not exist”