我正在使用piccopg2.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: sql…列上的执行失败"*“不存在”
发布于 2019-04-02 21:38:45
sql.Identifier('*')生成"*"
SELECT "*" FROM "schema"."table"使用基本的SQL可组合
qry = sql.SQL('SELECT {} FROM {}.{}').format(
sql.SQL('*'),
sql.Identifier('schema'),
sql.Identifier('table'))要获得
SELECT * FROM "schema"."table"https://stackoverflow.com/questions/55476466
复制相似问题