使用python的参数化postgresql select语句
如果我如上所述传递一个值,则select将其作为字符串。 这不是我们的意图 如果我尝试使用python的参数化postgresql select语句,python,postgresql,aws-lambda,amazon-redshift,psycopg2,Python,Postgresql,Aws Lambda,Amazon Redshift,Psycopg2,如果我如上所述传递一个值,则select将其作为字符串。 这不是我们的意图 如果我尝试 sql="select %s,tablename from pg_table_def where tablename like (%s)" data=("schemaname","abc",) cur.execute(sql,data) 然后显示错误全局名称“schemaname”未定义您不能以这种方式参数化对象名称(在本例中为列名)。您可以转而求助于字符串操作: data=(schemaname,"a
sql="select %s,tablename from pg_table_def where tablename like (%s)"
data=("schemaname","abc",)
cur.execute(sql,data)
然后显示错误
全局名称“schemaname”未定义
您不能以这种方式参数化对象名称(在本例中为列名)。您可以转而求助于字符串操作:
data=(schemaname,"abc",)
不能以这种方式参数化对象名(在本例中为列名)。您可以转而求助于字符串操作:
data=(schemaname,"abc",)