psycopg2 TypeError: not all arguments converted during string formatting

前端 未结 5 2071
[愿得一人]
[愿得一人] 2020-12-15 17:37

I\'m trying execute a simple query, but getting this error no matter how I pass the parameters.

Here is the query (I\'m using Trac db object to connect to a DB):

5条回答
  •  没有蜡笔的小新
    2020-12-15 18:03

    You should not use string interpolation for passing variables in database queries, but using string interpolation to set the table name is fine as long as it's not an external input or you restrict the allowed value. Try:

    cursor.execute("""SELECT name FROM %s.customer WHERE firm_id=%%s""" % schema, each['id'])
    

    Rules for DB API usage provides guidance for programming against the database.

提交回复
热议问题