psycopg2.ProgrammingError: column "your name" does not exist
psycopg2.ProgrammingError: column "your name" does not exist
当我尝试使用代码
上传PlayerScore
时
if Number.PlayerScore > Score.interact_database("SELECT Score FROM score WHERE Name = %s;" % Player_Name, False,)[0][0]
到 Python 中的 PostgreSQL 数据库 我收到此错误:psycopg2.ProgrammingError: column "your name" does not exist
,其中 'your name' 是变量 Player_Name。但是,当我在 PostgreSQL 查询工具中 运行 它工作正常。有谁知道为什么会弹出此错误以及如何防止它在将来再次发生?
http://initd.org/psycopg/docs/usage.html#the-problem-with-the-query-parameters
我认为我们需要查看更多代码,但根据文档:
Never, never, NEVER use Python string concatenation (+) or string parameters interpolation (%) to pass variables to a SQL query string. Not even at gunpoint.
尝试将参数作为 cursor.execute() 方法中的第二个参数传递。使用类似的东西:
cursor.execute("""SELECT Score FROM score WHERE Name = %(player)s""", {'player': player_name } )
cursor.fetchone()
应该可以。它还可以接受值的元组。
当我尝试使用代码
上传PlayerScore
时
if Number.PlayerScore > Score.interact_database("SELECT Score FROM score WHERE Name = %s;" % Player_Name, False,)[0][0]
到 Python 中的 PostgreSQL 数据库 我收到此错误:psycopg2.ProgrammingError: column "your name" does not exist
,其中 'your name' 是变量 Player_Name。但是,当我在 PostgreSQL 查询工具中 运行 它工作正常。有谁知道为什么会弹出此错误以及如何防止它在将来再次发生?
http://initd.org/psycopg/docs/usage.html#the-problem-with-the-query-parameters
我认为我们需要查看更多代码,但根据文档:
Never, never, NEVER use Python string concatenation (+) or string parameters interpolation (%) to pass variables to a SQL query string. Not even at gunpoint.
尝试将参数作为 cursor.execute() 方法中的第二个参数传递。使用类似的东西:
cursor.execute("""SELECT Score FROM score WHERE Name = %(player)s""", {'player': player_name } )
cursor.fetchone()
应该可以。它还可以接受值的元组。