你如何在 SQLAlchemy 中执行原始 SQL?
我有一个 python web 应用程序,它在 flask 上运行并通过 SQLAlchemy 连接到数据库。
我需要一种方法来运行原始 SQL。该查询涉及多个表连接以及内联视图。
我试过了:
connection = db.session.connection()
connection.execute( <sql here> )
但我不断收到网关错误。
原文由 starwing123 发布,翻译遵循 CC BY-SA 4.0 许可协议
你有没有尝试过:
要么:
请注意
db.engine.execute()
是“无连接”的, 在 SQLAlchemy 2.0 中已弃用。