Sql statement error: "column .. does not exist"

I need a postgres console for this command:

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 have this answer:

  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 just run the table:

 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 

... since we can see that the column exists.

maybe this is a syntax error, but I can't figure out what ...

Any help would be appreciated. Alessio

+6
source share
1 answer

No, the FK_Numbers_id column FK_Numbers_id not exist, only the "FK_Numbers_id" column "FK_Numbers_id"

Obviously, you created the table using double quotes, and so all column names are now case sensitive, and you must 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); 

Repeat what is already documented in the manual :

Column foo and foo identical, columns "foo" and "foo" are not.

+14
source

Source: https://habr.com/ru/post/912414/


All Articles