Reputation: 1
trying to use this query with escaped variables:
"UPDATE table_name SET status = ?, status_by = ? WHERE (unique_id, page_id) IN (?)", [req.body.action, req.body.status_by, aSet]
but end up getting this error: 'Operand should contain 2 column(s)'
this is how aSet looks: (1234567890, 123),(1234567890, 123)
Upvotes: 0
Views: 54
Reputation: 780724
You can't use a ?
placeholder for an entire list, it can only be replaced with a single value.
You need to spread the all the elements of aSet
into separate parameters, and put enough ?
placeholders in the query for all of them.
qs = ",".join(["(?, ?)"]*len(aSet))
sql = """UPDATE table_name SET status = ?, status_by = ?
WHERE (unique_id, page_id) IN (%s)"""%(qs)
cur.execute(sql, [req.body.action, req.body.status_by] + list(sum(aSet, ()))
I got that list(sum(aSet, ())
expression from Transform "list of tuples" into a flat list or a matrix
Upvotes: 1