6

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
  • ANY works with arbitrary operators, not just =
    – Bergi
    Dec 1, 2021 at 23:04

1 Answer 1

8

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.