【发布时间】:2019-05-28 22:03:32
【问题描述】:
试图创建一个动态过滤器,我在打印没有“引号”的 where 语句时遇到了困难。
输出:select "col1", "col2" from "table1" where "col2=1234" and "col3=column1"
所需:select "col1", "col2" from "table1" where col2="1234" and col3="column1"
def filter(table,*args,**kwarg):
query = sql.SQL("select {0} from {1} where {2}").format(
sql.SQL(', ').join(map(sql.Identifier,[arg for arg in args])),
sql.Identifier(table),
sql.SQL(' and ').join(map(sql.Identifier,{(str(k)+'='+str(v)) for k,v in kwarg.iteritems()}))
)
print query.as_string(Connection())
【问题讨论】: