[英]how to pass a python list in place of * in sql query
我有这种类型的 sql 字符串
"""select {} from public."myTempTable" where desc_id in (select desc_id from projectapp_description_table)
Except
select {} from projectapp_sitelink_table"""
我想在括号中传递一个 python 列表以执行
尝试这样的事情:
column_list = ['id', 'user', 'value']
my_string = 'select {0} from public.myTempTable where desc_id in (select desc_id from projectapp_description_table) ' \
'Except ' \
'select {0} from projectapp_sitelink_table'.format(", ".join('%s' % col for col in column_list))
print(my_string)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.