我使用带有各种占位符的查询写入数据库:
sql_write_ord = '''INSERT INTO rest_order_test (date_order, pos_line_id, pos_order_id, product_name, instructions, qty,
partner_name, status, to_wait, to_floor) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'''
order= '2016-06-10 16:36:53'
newTable = [12821, 4421, 'Crudo MD', 'Y', Decimal('1.0'), 'Mesa 10', 'A fazer', 'N', '0']
cur.execute(sql_write_ord,[order, newTable[0], newTable[1], newTable[2], newTable[3], newTable[4], newTable[5], newTable[6], newTable[7], newTable[8]])
是否有像
这样的优化解决方案cur.execute(sql_write_ord, ([order, newTable]))
没有生成' IndexError:列表索引超出范围'?
答案 0 :(得分:1)
您可以连接列表:
cur.execute(sql_write_ord, [order] + newTable)