How to combine multiple OR conditions #3049
-
Hello there, I'm currently writing a QueryDSL annotated based librairy that allow to simplifie querying postgrest in java Could you tell me how to write a simple case that contains multiple or on multiple variables ? My Case : StartDate => $SearchDate & EndDate is null or EndDate <= $SearchDate & StatusCode is Null or StatusCode is in ($SearchStatus) I understant according to the documentation that I have to write something like this Have you ever have to do this, and how. Best regards |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hi. I suggest converting your query to SQL first. I'm assuming this the filter you're looking for: WHERE
(StartDate => $SearchDate AND EndDate IS NULL)
OR (EndDate <= $SearchDate AND StatusCode IS NULL)
OR (StatusCode IS IN ($SearchStatus)) The
translates to
So, to simplify your query, it could be expressed like this:
Since these conditions have an
You can guide yourself with that example. If your query is different then express it in SQL, please. |
Beta Was this translation helpful? Give feedback.
-
Answer by @laurenceisla Postgrest accept multiple key params, so you can write It works also with complexe fonctions (or/not) |
Beta Was this translation helpful? Give feedback.
Hi. I suggest converting your query to SQL first. I'm assuming this the filter you're looking for:
The
or
operator will apply anOR
to all the elements inside, e.g. this:translates to
So, to simplify your query, it could be expressed like this:
Since these conditions have an
AND
between them, then you'll have to use theand()
operator inside (I added spacing it so you can see it better):