Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 01:34 PM
I'm trying to pass the elements of a tuple into a sql query using .format(). This works fine when I have multiple items in my tuple, but when using a single item in a tuple I get an error.
tuple1 = (1,2,3)
tuple2 = (5,)
combo = tuple1 + tuple2
print(combo)
query = ("""
select
case
when column in {tuple1} then 1
when column in {tuple2} then 2
end as check
from table
where column in {combo}
""".format(tuple1 = tuple1, tuple2 = tuple2, combo = combo))
print(query)Whenever I print the query it keeps the comma at the end of the single tuple which is what I think is causing the error.
I do want to continue to use a tuple because there are scenarios where I need to concatenate multiple tuples together.
Labels:
- Labels:
-
Format