问题描述:

I have a sql like:

DBSession().query(Model).filter(***)

and I want to explain this sql using SQLAlchemy.

网友答案:

Your filter call can be turned into a string:

query = str(DBSession().query(Model).filter(***))

You can then use that to ask for a MySQL explanation:

DBSession().execute('EXPLAIN ' + query)

You may have to include any bound parameters the filters added to your query as a dictionary:

DBSession().execute('EXPLAIN ' + query, {'param_1': 'value1', 'param_2': 'value2'})
相关阅读:
Top