'How to SQL DELETE a python generated list
I am not strong in SQL at all, and I tried searching around on how to convert my Python list into a proper format SQL. But I can only seem to convert into single separated tuples, instead of having all strings in one tuple.
Users_to_del = ['Aske Meyer', 'UserT', 'BUser', 'test3']
del_string1 = ', '.join([f"(\'{name}\')" for name in users_to_del])
sql = 'DELETE FROM users_from_group WHERE name_of IN %s;' % del_string1
print(sql)
cur.execute(sql)
The SQL query:
DELETE FROM users_from_group WHERE name_of IN ('Aske Meyer'), ('UserT'), ('BUser'), ('test3');
What I want to achieve:
DELETE FROM users_from_group WHERE name_of IN ('Aske Meyer', 'UserT', 'BUser', 'test3');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
