hey i am working with a sql query which works on filter which takes an array for filter, but my issue is that there might be a case when that filter array is not provided in that case i dont want to use that WHEN condition which filters using that array, so can i use some sort of if else in WHEN where if the provided array is empty i dont use that condition?
STILLWATER;
05/02/2022, 2:21 PM
Copy code
sql
AND ((ARRAY_LENGTH(country_filter,1) > 0 AND country = ANY(country_filter)) OR 1=1)
STILLWATER;
05/02/2022, 2:22 PM
this is the query i want to use if I send country filter array then i want to run country=ANY(filter) but if its empty i want it to skip the condition
g
garyaustin
05/02/2022, 2:47 PM
WHERE ARRAY_LENGTH(country_filter,1) = 0 OR country = ANY(country_filter)
Note: I'm not verifying the syntax you used and have not tested this.