2

I'm using sqlalchemy for python ORM , and I want to call a stored procedure which exists in postgresql. I can't find useful tutorials ,please tell me how to code.

Thank you very much

2 Answers 2

2

Using execute() on Connectionor Engine object, like:

result = conn.execute('SELECT procname(?,?)', 1, 2).fetchall()

Take a look at SQLAlchemy documentation for more info.

Sign up to request clarification or add additional context in comments.

Comments

-1

I don't know about any special classes SQLAlchemy provides for calling a procedure.

However you can always use simple select like:

SELECT * FROM proc(4,2);

2 Comments

This might be because what you have advised is deprecated now but following this I now get ProgrammingError: (psycopg2.errors.WrongObjectType) my_database.my_sp() is a procedure LINE 1: select * from my_database.my_sp... ^ HINT: To call a procedure, use CALL. [SQL: select * from my_database.my_sp();] (Background on this error at: sqlalche.me/e/f405)
This syntax is for calling a function. Procedures and functions are a little different in postgres than in sql server for example. If you need to return a result set, us a function. If you need to do some sort of operation that doesn't require a multi row result set, and just single row and a few columns/output parameters, then use procedures.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.