2017-01-03 138 views
0

執行此代碼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() 
+0

可能您的select返回多於1行,這是錯誤消息的原因。您可能希望將語法更改爲'insert ... select ...' – Shadow

回答

1

更改此時獲取的內部錯誤:

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 

並將最後兩個參數移至左側

+0

更改後我又收到另一個內部錯誤:InternalError:(1292,「截斷不正確的DOUBLE值:'lawson'」) –

+0

可能因爲目標列的精度不足以保持給定的值。 – GurV

0

你的陳述是錯誤的。嘗試:

INSERT INTO paragraphVector (termId, termFreq, kgram) 

SELECT termId , %s, %s 

FROM term WHERE term = %s AND kgram = %s 
相關問題