Python sqlalchemy调用存储过程

2024-06-16 11:37:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用sqlalchemypython调用stored procedure。我的代码如下:

@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)

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

我遵循了官方文件上的指示,但这并没有造成任何影响。在

我在python 3.5

有没有不同的方法来调用stored procedures?在


Tags: the代码getsqlalchemydefprocconnectionwrapper
1条回答
网友
1楼 · 发布于 2024-06-16 11:37:14

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

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

相关问题 更多 >