尝试在Azure中托管的数据库中插入pyodbc和python的字典列表时出错

问题描述 投票:-1回答:1

我正在尝试使用pyodbc和python插入字典列表但是我收到以下错误:

TypeError: ('Params must be in a list, tuple, or Row', 'HY000')

我在Azure中托管了一个数据库,我需要在表中插入1800多行,如下例所示

kp = {'documents': [
{'id': '1', 'keyPhrases': ['sport', 'baseball', 'aliens']},
{'id': '2', 'keyPhrases': ['play', 'capacity', 'tired']},
{'id': '3', 'keyPhrases': ['international', 'balance', 'boring']}
]

lst = []
for x in kp['documents']:
    for i in kp['keyPhrases']:
        lst.append({'keyphrases': i, 'paragraph_id': x['id']})
cursor.fast_executemany = True
sql = 'INSERT INTO keyphrases2 (keyphrases, paragraph_id) VALUES (% 
(keyphrases)s, %(paragraph_id)s'
cursor.executemany(sql, lst)
python azure pyodbc
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.