user8436761
user8436761

Reputation: 337

What is wrong with this Postgresql query in Python?

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

Not sure how to delete rows from the table when I am given a list of indices to be deleted.

Upvotes: 0

Views: 30

Answers (1)

JGH
JGH

Reputation: 17836

The second part of your query is not needed: just use the provided list.

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

You might have to build a comma-separated input, similar to

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

Upvotes: 2

Related Questions