【发布时间】:2021-03-28 15:52:46
【问题描述】:
我正在学习 PostgresSQL 作为一个新手,我遇到了这个名为“IndexError: tuple index out of range”的错误 我无法理解我在这方面做错了什么。这是完整的错误:
PS C:\Users\ketan\Documents\Python> & C:/Users/ketan/AppData/Local/Programs/Python/Python39/python.exe c:/Users/ketan/Documents/Python/error.py
Traceback (most recent call last):
File "c:\Users\ketan\Documents\Python\error.py", line 10, in <module>
update_table(20,16,'Apple')
File "c:\Users\ketan\Documents\Python\error.py", line 6, in update_table
cur.execute("UPDATE store SET quantity=%s, price=%s, item=%s WHERE item=%s",(quantity,price,item))
IndexError: tuple index out of range
这是我执行的代码:
import psycopg2
def update_table(quantity,price,item):
conn=psycopg2.connect("dbname='database1' user='postgres' password='(Your-own-password-please)' host='localhost' port='5432'")
cur=conn.cursor()
cur.execute("UPDATE store SET quantity=%s, price=%s, item=%s WHERE item=%s",(quantity,price,item))
conn.commit()
conn.close()
update_table(20,16,'Apple')
请给我一些解决方案!
【问题讨论】:
标签: python python-3.x database postgresql tuples