2

I have a problem with writing a Query using SQL ALchemy, I am running in Python 3.6. I need to filter the content of a column in my SQLite Database using parameters contained in an array. So far I have been using the following method to select elements from the database:

conn.execute(select([(mydatabase)]).where(mydatabase.c.filename == samplefile1 ))

Now however my program provides a list of possible files contained in an array:

files = [ filename1, filename2, filename3 ]

And I would like to create a query that automatically runs through the possible names provided in the array and selects them using a simple:

conn.execute(select([(mydatabase)]).where(or_(mydatabase.c.filename == filename1, mydatabase.c.filename == filename2 ... ect ))

Is there a way of automating this?? Or do I have to pass these all the time manualy? This is a problem as each time the program runs it will have a different number of possible names in the files array.

Can anyone help me how to figure this out? Is it possible to write this using a for loop?

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127

0 Answers0