Created
August 6, 2014 18:52
-
-
Save pawl/555e5eecce77d4de0ada to your computer and use it in GitHub Desktop.
Use List In Bind Parameters - SQLAlchemy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my_list = ['peach', 'grape', 'apple'] | |
query_parameters = {} | |
counter = 1 | |
for list_item in my_list: | |
query_parameters["list_item" + str(counter)] = list_item | |
counter += 1 | |
where_clause = 'fruits IN(:' + ",:".join(query_parameters.keys()) + ')' # create clause to be inserted into query | |
query_text = db.text(""" | |
SELECT | |
fruits | |
FROM table | |
WHERE """ + where_clause + """ | |
""") | |
result = db.engine.execute(query_text, **query_parameters) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment