We can check if a specific value is contained in an array using 'X' = ANY(haystack)
. However, how do I check if an array of integers contains a value that is less than X?, e.g. I want to find all arrays that have at least one value lower than 100.
1 Answer
Don't know if this is the answer, but one way of doing this is to create a range and then check if they overlap, e.g.
int4range(0, 100, '[]') @> ANY(t2.ages)
This works in cases when dealing with finite numbers, but would not work if ages
can contain any negative value.
Update: Never mind, it was just 100 >= ANY(t2.ages)
.
ANY
works with arbitrary operators, not just=