I can't find equivalent solution about Returning clause
DELETE FROM items
WHERE sub_item_id IN %(sub_item_ids)s
RETURNING item_id, sub_item_id,
I did this in SQLAlchemy :
purge_family = session.query(ItemItem).filter(ItemItem.sub_item_id.in_(sub_item_ids))
.delete(synchronize_session=False)
I need to return item_id, sub_item_id set upon execution of DELETE statement.
Pass the delete query to the execute () function and get all the results using fetchall () function. Use a for loop to iterate through the results. The SQLAlchemy query shown in the below code deletes the “non-fiction” genre this will effectively delete multiple rows at one go.
from sqlalchemy import delete Tablename.delete ().where (Tablename.c.column_name == value) Get the books table from the Metadata object initialized while connecting to the database. Pass the delete query to the execute () function and get all the results using fetchall () function. Use a for loop to iterate through the results.
For DELETE, the values are those of the rows which were deleted. Upon execution, the values of the columns to be returned are made available via the result set and can be iterated using CursorResult.fetchone()and similar.
The rendered UPDATE statement will emit the SET clause for each referenced column maintaining this order. Deprecated since version 1.4: The update.preserve_parameter_orderparameter will be removed in SQLAlchemy 2.0. Use the Update.ordered_values()method with a list of tuples. New in version 1.0.10. See also
To execute your query as is use Core constructs:
stmt = ItemItem.__table__.delete().\
where(ItemItem.sub_item_id.in_(sub_item_ids)).\
returning(ItemItem.item_id, ItemItem.sub_item_ids)
results = session.execute(stmt).fetchall()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With