0
votes

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.

1
Did you use double quotes? - Laurenz Albe
I did something like this ------cursor.execute("INSERT INTO analysis_result("user_id","E","A","C","N","O","total") VALUES (%s,%s,%s,%s,%s,%s,%s)",Result_lst) and i understand this in incorrect . can u help me with the correct way please @LaurenzAlbe - user14956888
Please share what your analysis_result-table looks like. No quotes of any kind should be necessary within the analysis_result(user_id,E,A,C,N,O,total)-part. To me, this error message sounds like there actually isn't any column named "e" in your table, but without seeing your table, I cannot confirm that or suggest any solutions - Lukas Thaler

1 Answers

0
votes

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)