I have a MySQL query issued from Python that looks like this:
foos: Sequence[str] = get_user_specified_strs()
# Return all the rows where `foo` is in `foos`.
# If `foos` contains the string '*', return everything.
results = await conn.query_rows(
'''
SELECT ...
WHERE
'*' IN %(foos)s
OR foo IN %(foos)s
...
''',
{'foos': foos}
)
The problem is that IN ()
is not valid in MySQL, so an empty foos
will cause the query to fail. Is there a way to write the query without requiring assembling the SQL string dynamically, so that it can handle this case? I.e., treating IN ()
as FALSE
.