1
import psycopg2

conn=None
try:
 conn=psycopg2.connect(database="LIS", user="postgres",password="postgres",host="localhost",port=5432)
except:
    print("Unable to connect")

if conn:
    id="FCS01"
    cur=conn.cursor()
    query="""
    SELECT faculty_fname FROM faculty where id=?
    """
    cur.execute(query,(id,))
    rows=cur.fetchall()
    print(rows[0][0])

It gives an error No operator matches the given name and argument type. You might need to add an explicit type cast. however it work when we directly write value of id like-

SELECT faculty_fname FROM faculty where id="FCS01"
davidism
  • 121,510
  • 29
  • 395
  • 339
  • What is the column type for `faculty_fname.id`, integer, text, character varying? – mike.k Dec 16 '21 at 15:02
  • 2
    Isn't the syntax ```where id=%s```, per https://www.psycopg.org/docs/usage.html#passing-parameters-to-sql-queries? Looks fine otherwise – user23952 Dec 16 '21 at 15:06

0 Answers0