Skip to content
Advertisement

column “e” of relation “analysis_result” does not exist

connection to postgresql database has been connected successfully.but while executing below query i am getting some kind of error which looks like :

column “e” of relation “analysis_result” does not exist LINE 1: INSERT INTO analysis_result(user_id,E,A,C,N,O,total) VALUES …

        cursor = connection.cursor()
        print("inside execution ")
        cursor.execute("INSERT INTO analysis_result(user_id,E,A,C,N,O,total) VALUES (%s,%s,%s,%s,%s,%s,%s)",Result_lst)

i understand what is the error .i have to put each of E A C N O in quotes but while quoting them my sql query becomes invalid .Please give me a solution i am scraching my head for quite sometime now. and Result_lst=[1,20,14,14,38,8]. Result_lst will be dyanamic values in integer forms.

Advertisement

Answer

If the column name contains upper case characters, you must surround it with double quotes, otherwise PostgreSQL will fold it to lower case (note the error message).

But you cannot simply use double quotes because that’s what you used for the Python string.

Either use single quotes with the Python string:

cursor.execute('INSERT INTO analysis_result(user_id,"E","A","C","N","O",total) ...', Result_lst)

or escape the double quotes:

cursor.execute("INSERT INTO analysis_result(user_id,"E","A","C","N","O",total) ...", Result_lst)
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement