繁体   English   中英

psycopg2.ProgrammingError:“您的姓名”列不存在

[英]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 ,其中“您的名字”是变量Player_Name。 但是,当我在PostgreSQL查询工具中运行它时,它运行良好。 有谁知道为什么会出现此错误,以及如何防止将来再次发生?

http://initd.org/psycopg/docs/usage.html#the-problem-with-the-query-parameters

我认为我们需要查看更多代码,但根据文档:

从不,从不,从不使用Python字符串串联(+)或字符串参数插值(%)将变量传递给SQL查询字符串。 甚至没有枪口。

尝试将参数作为您的cursor.execute()方法的第二个参数传递。 使用类似:

cursor.execute("""SELECT Score FROM score WHERE Name = %(player)s""", {'player': player_name } )
cursor.fetchone()

应该管用。 它也可以接受值的元组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM