Как использовать переменные в SQL-запрос в Python - PullRequest
0 голосов
/ 09 июня 2018

Я пытаюсь сделать банковскую систему и ее одну из функций, которые я определил

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.*

Может кто-нибудь сказать мне, что с ним не так?

1 Ответ

0 голосов
/ 09 июня 2018
cur.execute('''SELECT id, name, acc_no, ph_no,address, email,balance
               FROM accounts
               WHERE id = %s and acc_no = %s''',
            (str(temp_pass), str(temp_accno)));
...