我正在使用 psycopg2.sql 动态生成查询字符串。
我希望能够将列列表或 *(对于所有列)动态传递给同一个 SELECT 查询字符串。
这适用于列列表:
qry = sql.SQL('SELECT {} FROM {}.{}').format(
sql.SQL(",").join(map(sql.Identifier, ["col1","col2"])),
sql.Identifier('schema'),
sql.Identifier('table'))
但这在尝试选择所有列时不起作用:
qry = sql.SQL('SELECT {} FROM {}.{}').format(
sql.Identifier('*')),
sql.Identifier('schema'),
sql.Identifier('table'))
我收到的错误是“DatabaseError: Execution failed on sql … column "*" does not exist”
牛魔王的故事
相关分类