hey i am working with a sql query which works on f...
# sql
s
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?
Copy code
sql
AND ((ARRAY_LENGTH(country_filter,1) > 0 AND country = ANY(country_filter)) OR 1=1)
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
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.
s
got it working few tweaks thanks