PostgreSQL - ERROR: the "codpais" column does not exist SQL state: 42703

1

Hello Any help to correct this problem in PostgreSQL 9.6

I have a query made by the graphic assistant, which shows the automatic code:

SELECT * FROM public.pais
ORDER BY "CodPais" ASC 

The previous code shows the results of the country table but when I do the same query replacing the * with the fields in the table as follows:

SELECT CodPais, NomPais FROM public.pais
ORDER BY "CodPais" ASC

throws the following error:

  

ERROR: the "codpais" column does not exist LINE 1: SELECT CodPais, NomPais   FROM public.pais                  ^ HINT: You probably want to refer to the column «country.CodPais».   ********** Error **********

     

ERROR: the "codpais" column does not exist SQL state: 42703 Hint: You probably want to refer to the column «country.CodPais».   Character: 8

That same error throws me with all the tables of the database when doing query by fields, I had PostgreSQL 9.6.4 and now I tried with the 9.6.5 after formatting my pc.

Note: In SQL Server 2016 Express works 100%, I am about to keep my traditional DBMS (SQL Server); but first I want to see if someone helps me with this error, so far is my only disappointment with postgreSQL.

    
asked by Karakal 08.09.2017 в 02:14
source

2 answers

1

It should work if you write the query like this:

SELECT "CodPais", "NomPais" FROM public.pais ORDER BY "CodPais" ASC;

Or so:

SELECT "pais"."CodPais", "pais"."NomPais" FROM public.pais ORDER BY "pais"."CodPais" ASC;

If it does not work in any of these ways, you will need to review the columns in your table with a query like this:

SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = 'public.pais';

Remember to respect the case sensitive when you write the identifiers, since it is not the same CodPais as codpais or codPais or CODPAIS or cOdPaiS or any other combination.

    
answered by 08.09.2017 в 06:59
0

The same thing happened to me and you have two options. 1- use column name in lowercase 2. If you want to use capital letters you must enclose them in quotes, a good tool is pgadmin as an interface there you will understand it better. SELECT "CodPais", "NomPais" FROM public.pais ORDER BY "CodPais" ASC

    
answered by 10.09.2017 в 03:24