Postgresql Column Doesn't Exist

superblowncolon picture superblowncolon · Aug 24, 2018 · Viewed 7.6k times · Source

I'm running a simple select query:

SELECT return_part_i.CntrctTrmntnInd FROM return_part_i LIMIT 10;

And getting the following error:

ERROR: column return_part_i.cntrcttrmntnind does not exist LINE 1: SELECT return_part_i.CntrctTrmntnInd FROM return_part_i LIMI... ^ HINT: Perhaps you meant to reference the column "return_part_i.CntrctTrmntnInd". SQL state: 42703 Character: 8

I have tried the query with and without the table identifier. I am copying the field name directly from the hint. This is happening with numerous fields in the database.

Answer

ScaisEdge picture ScaisEdge · Aug 24, 2018

if you really have a camel case in you column name then you must wrap the column name with double quote

SELECT "CntrctTrmntnInd"  FROM return_part_i LIMIT 10;

PostgreSQL columns (object) name are case sensitive when specified with double quotes. Unquoted identifiers are automatically used as lowercase so the correct case sequence must be write with double quotes

and as correctly suggested by Raymond Nijland if you want a LIMIT in result you should use an order by

SELECT "CntrctTrmntnInd"  FROM return_part_i ORDER BY "CntrctTrmntnInd" LIMIT 10;