I am using Flask-SQLAlchemy, and I am having some trouble with the IN clause in the SQL syntax. The data I want my IN clause to "read" is a list with some data, for example
args = [1, 2, 3]
here is how my code looks like.
connection = db.session.connection()
raw_sql = text("""
SELECT
*
FROM
table
WHERE data IN :list
""")
query = connection.engine.execute(raw_sql, {'list' : args})
I have tried giving inserting tuples and list to the args parameter, but nothing have worked. I am either getting:
args = tuple([1, 2, 3])args = [1, 2, 3]
how do you read from a list with SQLAlchemy and using RAW SQL and parameters as an input?
On python 3.7:
import sqlalchemy
args = [1, 2, 3]
raw_sql = "SELECT * FROM table WHERE data IN :values"
query = sqlalchemy.text(raw_sql).bindparams(values=tuple(args))
conn.engine.execute(query)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With