Use placeholder %s with SQLAlchemy 2.x

38 Views Asked by At

I want/need to update my project from SQLAlchemy 1.4 to SQLAlchemy 2.x.

Is there a way to use the placehoder %s with a list of arguments in the execute()function without running the query multiple times?

This is how it worked in SQLALchemy 1.4:

conn.execute(
    "SELECT * FROM users WHERE name = %s AND age = %s",
    ['roy', 45]
)

But now it runs the query for each entry of the list.

I have used this over 100 times in my project, so I am not happy with this change unless the old way does not work.

0

There are 0 best solutions below