SQLAlchemy:在绑定参数的旁边打印实际的原始SQL查询

时间:2018-10-29 09:42:12

标签: python sqlalchemy

很清楚,已经进行了类似的讨论(here),但是我的问题与那些必须执行原始SQL的情况有关。 给定S QLAlchemy official documentation中的以下示例:

>>> from sqlalchemy.sql import text
>>> s = text(
...     "SELECT users.fullname || ', ' || addresses.email_address AS title "
...         "FROM users, addresses "
...         "WHERE users.id = addresses.user_id "
...         "AND users.name BETWEEN :x AND :y "
...         "AND (addresses.email_address LIKE :e1 "
...             "OR addresses.email_address LIKE :e2)")
>>> conn.execute(s, x='m', y='z', e1='%@aol.com', e2='%@msn.com').fetchall()

如何打印带有参数的实际SQL statemet?

0 个答案:

没有答案