【问题标题】:How to call the stored procedure with parameters in python?如何在python中调用带参数的存储过程?
【发布时间】:2019-11-27 01:36:13
【问题描述】:

我定义了一个存储过程escalate,它采用字符串参数clientid

我在 python 中使用 sqlalchemy 并使用 ORM。我创建了 db.session。

我不确定如何使用此会话调用存储过程。

谁能告诉我解决办法?

我已尝试关注;但出现错误:

TypeError: get_bind() 得到了一个意外的关键字参数 'param'

代码:

from sqlalchemy import and_, func,text

db.session.execute(text("CALL escalate(:param)"), param=clientid)

【问题讨论】:

    标签: python sqlalchemy flask-sqlalchemy


    【解决方案1】:

    From the docs session.execute 需要一个超过 kwargs 的字典,unlike the connection object 应该按照你写的那样工作。

    db.session.execute(
        "CALL escalate(:param)",
        {'param': clientid}
    )
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    • 2011-11-24
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    相关资源
    最近更新 更多