I see a couple of issues with the snippet you shared
- the delete syntax in postgresql is
delete from <tablename> where ...
- company_id seems to be a string but in values its expressed as an integer.
you can either execute multiple queries to delete the records or you can pass a list of values to compare against the compound field (company_id, product_id)
& use execute_values
assuming company_id is text & your values list contains strings
multiple queries:
stmt = "delete from products where company_id = %s and product_id = %s"
cur.execute('begin')
try:
for cid, pid in values:
cur.execute(stmt, (cid, pid))
cur.execute('commit')
# do other things
except:
cur.execute('rollback')
# do other things to handle this exception
one query + execute_values
from postgresql.extras import execute_values
stmt = "delete from products where (company_id, product_id) IN (%s)"
execute_values(cur, stmt, values)
The psycopg2.extras
documentation page contains lots of helpful functions, including documentations for execute_values