简体   繁体   中英

How can I delete an all recods matched?

I have the code like:

from sqlalchemy import func
d = func.date('2021-6-23')
session.query(XCom).filter(XCom.execution_date <= d).delete()

feedback is :

File "/home/airflow/.local/lib/python3.6/site-packages/sqlalchemy/orm/query.py", line 3926, in delete
delete_op.exec_()

I have tried:

session.query(XCom).filter(XCom.execution_date <= d).all()

it worked.

I cannot find out a reference for this. Any helps would be appreciated!

I found in sqlalchemy page

just add synchronize_session=False inside delete()

session.query(XCom).filter(XCom.execution_date <= d).delete(synchronize_session=False)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM