執行此代碼InternalError該:(1242, '子查詢返回多於1行')
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()
可能您的select返回多於1行,這是錯誤消息的原因。您可能希望將語法更改爲'insert ... select ...' – Shadow