Let's take a simple SELECT
query:
@SqlQuery("SELECT * FROM mytable WHERE some_column = :myVar")
List<MyObjects> getBySomeColumn(String myVar);
I'd like to know if there is something like the above, but handles both IS NULL
and =
similarly, automatically:
@SqlQuery("SELECT * FROM mytable WHERE some_column <MAGIC_HERE> :myVar")
List<MyObjects> getBySomeColumn(String myVar);
... which would run either:
SELECT * FROM mytable WHERE some_column IS NULL
or
SELECT * FROM mytable WHERE some_column = :myVar
... depending on whether myVar
is null
or not. What is the most idiomatic way to handle this kind of query?
There are two options:
SELECT * FROM mytable
WHERE (:myVar is null and some_column is null) or some_column = :myVar