I am building a select query and adding elements to it programmatically. The problem is that I need the values tuple to have a trailing comma. How can I do this?
def build_search_query(user_list, make, model, price_min, price_max):
sql = """SELECT * FROM mycolumn WHERE user_id = %s, """
for i, d in enumerate(user_list):
if not i == 0: #skip first user because its already in sql
next_user = "OR user_id = %s, "
sql += next_user
age_str = "AND age = %s, "
height_str = "AND height = %s, "
price_min_str = "AND price > %s, "
price_max_str = "AND price < %s "
sql += age_str
sql += height_str
sql += price_min_str
sql += price_max_str
tuple1 = tuple(user_list)
tuple2 = (age, height, price_min, price_max,)
values = tuple1 + tuple2 #this is where I need the trailing comma
return sql, values
build_search_queryis being called or what happens to the return values.