Python sqlalchemy 调用存储过程

PYA*_*PYA 3 python sqlalchemy pyodbc python-3.x

我试图调用stored procedurepython使用sqlalchemy。我的代码如下:

@database_connection_wrapper
def get_adv(connection):
    ''' get the adv using a stored proc from the database '''

    connection.callproc("GetAdvMedianTrailing30Days")
    results = list(connection.fetchall())
    print(results)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误: AttributeError: 'pyodbc.Connection' object has no attribute 'callproc'

我按照官方文档上的说明进行操作,但这并没有什么区别。

我在 python 3.5

有不同的调用方式stored procedures吗?

cow*_*ert 5

来自https://github.com/mkleehammer/pyodbc/wiki/Calling-Stored-Procedurespyodbc没有.callproc()在连接对象上实现方法。您必须使用 SQL 调用 ( .execute("{CALL GetAdvMedianTrailing30Days}"))来执行 sp 。

(这不是真正的 SQLAlchemy 问题,因为您正在泄漏抽象以使用 进行 DB-API 调用pyodbc