【发布时间】:2023-04-06 17:35:01
【问题描述】:
我尝试按照 docs 中描述的方式传递参数,但出现以下错误: 文件“slug_word.py”,第 100 行,在 get_col cur.execute("从 %s 中选择 %s" , data ) psycopg2.ProgrammingError:“E'catalog_category'”处或附近的语法错误 第 1 行:从 E'catalog_category' 中选择 E'slug'
以下是我的代码摘录:
def get_col(cxn, table, col):
"fetch a column"
cur = cxn.cursor()
data = (col, table)
cur.execute("select %s from %s" , data )
rows = cur.fetchall()
return rows
def main():
cxn = connect('galleria')
table = 'catalog_category'
col = 'slug'
rows = get_col(cxn, table, col)
【问题讨论】:
标签: parameters psycopg2