0
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.

1 Answer 1

2

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)))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.