Ratha
Ratha

Reputation: 9692

How to call the stored procedure with parameters in python?

I have a stored procedure defined escalate which taking a string parameter clientid.

I'm using sqlalchemy in python and using ORM. I have db.session created.

I'm not sure how i could call stored procedure with this session.

Anyone could point me the solution?

I have tried following; but getting an error:

TypeError: get_bind() got an unexpected keyword argument 'param'

Code:

from sqlalchemy import and_, func,text

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

Upvotes: 0

Views: 488

Answers (1)

Kirk
Kirk

Reputation: 1845

From the docs session.execute needs a dict over kwargs, unlike the connection object which should have worked as you wrote it.

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

Upvotes: 1

Related Questions