select query on postgis not working for specific fields [closed]

Posted on

Question :

So I have what seems to be a really weird problem.

I have imported a table from QGIS into a postgresql + postgis database.
I simply want to select a few columns from that, but I can’t. enter image description here

whats funny is that i can use the select query for the lowercase fields and it works, but not for the uppercase ones, such as LABELRANK. the error shows that such a column does not exist.

why is that so?

Answer :

Probably this columns names has been created using double-quotes.

You should use double-quotes in your SELECT statement.

create table tbl (field1 int, "FIELD2" int, field3 int);
insert into tbl values (1,2,3),(4,5,6);
select field1, field2, field3 from tbl;
ERROR:  column "field2" does not exist
LINE 1: select field1, field2, field3 from tbl;
                       ^
HINT:  Perhaps you meant to reference the column "tbl.field1" or the column "tbl.field3".

select field1, "FIELD2", field3 from tbl;
field1 | FIELD2 | field3
-----: | -----: | -----:
     1 |      2 |      3
     4 |      5 |      6

db<>fiddle here

Leave a Reply

Your email address will not be published. Required fields are marked *