Executing a SQL depending on the existence of a parameter

Hi, I would like to know if its possible to add some type of IF statement to parameters for the queryLambda,

My use case is that if I do not provide a parameter I would like to do SELECT all, but if the parameter was specified I would like to use it on the WHERE clause.



You can set a default value for the parameter to indicate that the parameter was not provided explicitly, and then write your query like the following:

WHERE field = :param OR :param = <default_value>

Does that work for your use case?

Hey @renner.g there’s a small mistake in the above suggestion to give you the ability to get all values or just the ones equal to what was provided in the parameter.
The pattern is:

WHERE ( :parameter_a = <default_value>
OR  col_a = :parameter_a)

So for example if I had a column named Size and had sizes S,M,L,XL and wanted to get all values I would set the default value for a parameter named size_selector as ‘O’ (something that doesn’t exist as a value in the field) and the where clause to:

WHERE :size_selector = 'O' or size = :size_selector

and when sending the value through QL if it’s not specified it will return all values since ‘O’ = ‘O’ and if it is specified (for example if it is ‘S’) it will return all documents where size =‘S’ (since ‘S’ doesn’t equal ‘O’)
Let me know if this makes sense or if you have any other questions.