3

I'm using sqlalchemy in a flask application that connects to multiple databases, using binds as shown here. I want to execute a raw sql query on one of the non-primary databases.

I'm trying to use session.execute, as shown here but it executes for the primary db. The API docs state that you can use a parameter: "bind – Optional Engine to be used as the bind". How do I access and specify the bind for the non-primary db and call session.execute to execute a query for that db?

Alternately, is there any other way to go about it?

1 Answer 1

6

Try this:

from flask import current_app
db.get_engine(current_app, bind='<your_bind>').execute('<your raw sql>')
Sign up to request clarification or add additional context in comments.

Comments

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.