I want to write the following SQL query efficiently with SQLAlchemy.
UPDATE item_recs
SET deleted_at = :deleted_at
WHERE project_id = :project_id
AND item_id IN (1602,1603,1604)
I have a corrosponding SQLAlchemy model ItemRec
that has item_id
, project_id
, and deleted_at
as columns. It also has an id
which is an auto-incremented primary key.
Also, I am running the above query with session.execute()
method in SQLAlchemy. Right now I am just joining the item_ids in the IN
clause and concatenating it with the rest of the query. Is there a way to build this IN
clause with placeholders like :project_id
instead of using string concatenation?