Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
208 views
in Technique[技术] by (71.8m points)

python - 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...