【发布时间】:2018-06-09 17:49:21
【问题描述】:
我正在尝试创建一个银行系统及其我定义的功能之一
def fetch(temp_pass,temp_accno):
cur.execute("SELECT id,name,acc_no,ph_no,address,email,balance from accounts where id = %s and acc_no = %s",(temp_pass,temp_accno,))
row = cur.fetchall();
return row
这是我得到的错误
*\Traceback (most recent call last):
File "Accounting.py", line 126, in <module>
deposit()
File "Accounting.py", line 79, in deposit
fetch(temp_pass,temp_accno)
File "Accounting.py", line 8, in fetch
cur.execute("SELECT id,name,acc_no,ph_no,address,email,balance from accounts where id = %s and acc_no = %s",(temp_pass,temp_accno,))
psycopg2.ProgrammingError: operator does not exist: character = integer
LINE 1: ...h_no,address,email,balance from accounts where id = 1234 and...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.*
谁能告诉我它有什么问题?
【问题讨论】:
-
是 temp_pass,temp_accno 是 int 值或字符串值,还要去掉
temp_pass,temp_accno,后多余的逗号,应该是temp_pass,temp_accno -
它们是 int 值
-
你试过去掉多余的逗号吗?
-
另外,试试这个
cur.execute("SELECT id,name,acc_no,ph_no,address,email,balance from accounts where id = " + temp_pass + " and acc_no = " + temp_accno) -
那没用,但我现在正确了
标签: python-3.x psycopg2 postgresql-9.5