I would like to select all possible values when em...
# squarelibraries
k
I would like to select all possible values when empty list/null is passed to function or filtered values when selected filters are passed to the function. Recently I went through #1719 and it works great for single “id”:
Copy code
WHERE (season = :season OR :season IS NULL)
Is it possible to achieve the same for collection of “ids” (with
IN
operator)? The following code doesn’t work, because it generates expected type as
Collection<Season?>
instead of
Collection<Season>?
and generally it’s not handled properly
Copy code
WHERE (season IN :season OR :season IS NULL)
To overcome this issue I use the following statement:
Copy code
WHERE CASE WHEN :seasonIsEmpty THEN TRUE ELSE season IN :season END
and it works great. However it forces me to introduce additional variable (
seasonIsEmpty
) which seems not optimal. I would expect that at least the following code should work:
Copy code
WHERE CASE WHEN :season IS NULL THEN TRUE ELSE season IN :season END
but it also generates
Collection<Season?>
instead of
Collection<Season>?
Is there a way to simplify this statement?
d
You're kinda abusing NULL there. This is one of those times when I think SQLDelight is a bit too sugary.