执行此代码时出现内部错误

conn = pymysql.connect(user = 'root', password = '', unix_socket = "/tmp/mysql.sock", database = 'abc' )
cursor = conn.cursor()
 query2 = """INSERT INTO paragraphVector (termId, termFreq, kgram) VALUES ((SELECT termId FROM term WHERE term = %s AND kgram = %s), %s, %s)"""

insertDocVec = [(str(term), str(kgram), tf[kgram][term], str(kgram)) for kgram in tf for term in tf[kgram]]
cursor.executemany(query2, insertDocVec)
conn.commit()

最佳答案

更改此:

INSERT INTO paragraphVector (termId, termFreq, kgram) VALUES ((SELECT termId FROM term WHERE term = %s AND kgram = %s), %s, %s)


对此:

INSERT INTO paragraphVector (termId, termFreq, kgram) SELECT termId, %s, %s FROM term WHERE term = %s AND kgram = %s


并将最后两个参数向左移动

09-30 22:30