Python中的此Postgresql查询有什么问题?

时间:2019-01-07 19:15:15

标签: python-3.x postgresql

q = """DELETE FROM my_table
       WHERE id in ({}) (select id from ({}))""".format(list_of_ids_to_be_deleted)

当获得要删除的索引列表时,不确定如何从表中删除行。

1 个答案:

答案 0 :(得分:2)

不需要查询的第二部分:只需使用提供的列表即可。

q = """DELETE FROM my_table
       WHERE id in ({})""".format(list_of_ids_to_be_deleted)

您可能需要构建逗号分隔的输入,类似于

q = """DELETE FROM my_table
       WHERE id in ({})""".format(','.join(map(str, list_of_ids_to_be_deleted)))