关键需要使用text

from sqlalchemy import create_engine, text

sql = 'SELECT * FROM my_table WHERE account_id = :account_id and amount =: amount' session.execute( text(sql), {
"account_id": 100000, "amount": 500} )

 传入list

sql_tmpl = "delete from Data where id_data in :iddata"
params = {  
   'iddata':(1, 2, 3, 4),  # tuple
}
self.session.execute(text(sql_tmpl), params) 

https://stackoverflow.com/questions/13190392/how-can-i-bind-a-list-to-a-parameter-in-a-custom-query-in-sqlalchemy

posted on 2019-08-08 21:36  Go_Forward  阅读(570)  评论(0编辑  收藏  举报